0

我有一个模型用户,它有一个 user_profile 和一个 User_Profile belongs_to 用户

在用户控制器中,我有:

  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%>

在我的轮回中:

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

现在奇怪的是我可以做到:

users/1/personal 

查看表单,但是当我提交时出现此错误:

Unknown action

No action responded to 1.

它试图找到一个名为 1 的动作。

谁能指出我正确的方向?

4

1 回答 1

0

刚刚又遇到了问题,终于明白了问题,找到了解决办法。

这次我使用 getJason 进行 ajax 调用。因为调用是一个 get,并且在我的路由中我有一个 update_xxxxxx => :put,所以路由被忽略并使用默认的 :controller/:action/:id。

我只需要输入 update_xxxx => :get 问题就解决了。

也许这会对某人有所帮助。

于 2010-05-17T23:54:41.903 回答