【发布时间】:2011-08-31 02:20:57
【问题描述】:
我一直在阅读 this resource 和 this post 以尝试更多地了解 Routes(目前正在通过实践学习编程/Rails),但我想知道如何解决我遇到的错误,即 @ 987654323@。
我在使用嵌套模型表单完成 Rails 3 注册过程时遇到错误。注册流程,如下:
user = User.new
user.email = ""
user.password = ""
user.profile = Profile.new
user.profile.save
user.save
注册过程从主页开始,表格如下:
<%= form_for :user, :url => signup_path, :html => {:id => 'homepage'} do |f| %>
<div>
...
</div>
<%= f.fields_for :profile do |f| %>
<% end %>
<% end %>
然后该过程会填写个人资料,然后在完成此表单后重定向到新用户的个人资料:
<%= form_for :profile, :html => { :multipart => true } do |f| %>
<div>
...
</div>
<%= f.fields_for :user do |f| %>
<% end %>
<% end %>
我在他们各自的模型中有accepts_nested_attributes_for :user and :profile。
我的 rails 服务器给了我更多的细节:
ActionController::RoutingError (No route matches {:controller=>"profile.save", :action=>"show"}):
app/controllers/profiles_controller.rb:15:in `create'
所以在我的 ProfilesController 中的“创建”中:
def create
@profile = Profile.new(params[:profile])
if @profile.save
redirect_to profile_path, :notice => 'User successfully added.'
else
render :action => 'new'
end
end
似乎很明显问题出在profile_path,所以我的Routes.rb:
post "/signup" => "profiles#create", :as => "signup"
match "skip/signup", :to => "info#signupskip"
match "skip/profiles/new", :to => "profiles#newskip"
root :to => "users#create"
谁能帮助阐明我在 Routes.rb 文件中做错了什么/遗漏了什么?
【问题讨论】: