创建与特定帐户关联的人员后,如何重定向回帐户页面?重定向到另一个控制器中的SHOW操作
的ACCOUNT_ID通过URL参数传递给CREATE人称动作如下:
http://localhost:3000/people/new?account_id=1
下面是代码:
<h2>Account:
<%= Account.find_by_id(params[:account_id]).organizations.
primary.first.name %>
</h2>
<%= form_for @person do |f| %>
<%= f.hidden_field :account_id, :value => params[:account_id] %><br />
<%= f.label :first_name %><br />
<%= f.text_field :first_name %><br />
<%= f.label :last_name %><br />
<%= f.text_field :last_name %><br />
<%= f.label :email1 %><br />
<%= f.text_field :email1 %><br />
<%= f.label :home_phone %><br />
<%= f.text_field :home_phone %><br />
<%= f.submit "Add person" %>
<% end %>
class PeopleController < ApplicationController
def new
@person = Person.new
end
def create
@person = Person.new(params[:person])
if @person.save
flash[:success] = "Person added successfully"
redirect_to account_path(params[:account_id])
else
render 'new'
end
end
end
当我提交上述形式出现以下错误消息:
Routing Error
No route matches {:action=>"destroy", :controller=>"accounts"}
为什么redirect_to路由到DESTROY操作?我想通过SHOW操作重定向。任何帮助将不胜感激。
'耙路线'并检查所有生成的路线,看看你缺少什么。 –
问题不是缺失的路线。他只是试图路由到'account_path(nil)'。 – numbers1311407