rails3:动作被路由到错误的控制器。可能的错误?

时间:2012-07-02 09:33:34

标签: ruby-on-rails-3 controller rails-routing

我有两个模型(用户和配置文件)与1对1关联。

class Profile < ActiveRecord::Base
  attr_accessible :language_tokens, :tele, :languages, :serviceDesc, :service
  belongs_to :user
  ...

class User < ActiveRecord::Base
  has_one :profile, dependent: :destroy

使用以下命令构建配置文件:

@profile = @user.build_profile(session[:form_params])

我的个人资料编辑表单只是一个标准表单,应在提交时路由到我的个人资料更新操作。

<%= form_for @profile do |f| %>
  <%= render 'shared/host_information', :f => f%>
  <%= render 'shared/service_information', :f => f%>
  <%= f.submit 'done', class: "bnt"%>
<% end %>


HTML form:
<form id="edit_profile_6" class="edit_profile" method="post" action="/profiles/6" accept-charset="UTF-8">

但是,由于某些奇怪的原因,表单正在提交用户更新,而不是预期的个人资料更新。我在用户更新中添加了一个调试点,您可以看到params确认目标控制器确实应该是profiles_controller。

/railsapp/loco_app/app/controllers/users_controller.rb:82
@user = User.find_by_id(params[:id])
(rdb:15) p params
{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"qXx5EWwIWASiARKVFE7eDd43gHnBSmK538YAXeesDyI=", "profile"=>{"country_id"=>"8", "city_id"=>"22", "tele"=>"", "language_tokens"=>"18,14", "service"=>"9",  },
"commit"=>"done", "action"=>"update", "controller"=>"profiles", "id"=>"6"}
(rdb:15)

以下是相关路线:

profiles POST   /profiles(.:format)                   profiles#create
new_profile GET    /profiles/new(.:format)               profiles#new
edit_profile GET    /profiles/:id/edit(.:format)          profiles#edit
profile PUT    /profiles/:id(.:format)               profiles#update

users GET    /users(.:format)                          users#index
POST   /users(.:format)                          users#create
new_user GET    /users/new(.:format)                      users#new
edit_user GET    /users/:id/edit(.:format)                 users#edit
user GET    /users/:id(.:format)                      users#show
PUT    /users/:id(.:format)                      users#update
DELETE /users/:id(.:format)                      users#destroy

调试此问题的最佳方法是什么?这是一对一关联的一些奇怪的副作用还是这里有一个错误?我正在使用rails 3.2.2。

*的 更新 * 所以这绝对看起来像一个bug。我重新生成了我的控制器(同名)并复制了相同的代码,现在它正在工作,没有任何其他更改。我仍然有兴趣了解这是否是一个已知问题,以及如何在将来调试此类问题。

0 个答案:

没有答案