2010-05-14 45 views
0

我有HAS_ONE user_profile模型的用戶,並在用戶控制器User_Profile belongs_to的用戶路由使用ID已經動作和動作已經提交表單

後ID我:

def personal 
    @user = User.find_by_id(params[:id]) 
    @user_profile = @user.user_profile 
    @user_profile ||= @user.build_user_profile 
    end 

    def update_personal 
    @user = User.find_by_id(params[:id]) 
    if @user.user_profile.update_attributes(params[:user_profile]) 
     flash[:notice] = "OK" 
     redirect_to @user 
    else 
     flash[:notice] = "Fail" 
     render :action => 'update_personal' 
    end 
    end 

在我personal.html.erb觀點我有:

<% semantic_form_for @user_profile, :url => { :action => "update_personal"} do |form| %> 
    <%= form.inputs %> 
    <%= form.buttons %> 
<%end%> 

而且在rountes我:

map.resources :users, :member => { 
     :personal   => :get, 
     :update_personal  => :put 
     } 

現在奇怪的是,我可以這樣做:

users/1/personal 

看到的形式,但是當我提出我得到這個錯誤:

Unknown action 

No action responded to 1. 

它試圖找到與該名字的動作1.

任何人都可以指出我正確的方向嗎?

+0

經過很多小時試圖找出這一個......這很簡單。 只需重新啓動服務器。 X_X – 2010-05-14 18:42:39

回答

0

我剛剛得到了問題,終於明白了問題,並找到了解決辦法。

這次我使用的是使用getJason的ajax調用。 因爲呼叫是一個get,而在我的路由中,我有一個update_xxxxxx =>:put, 該路由被忽略,並且使用了默認值:controller /:action /:id。

我只是把update_xxxx =>:get並且問題解決了。

也許這會幫助別人。