2010-05-14 48 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并且问题解决了。

也许这会帮助别人。