創建與特定帳戶關聯的人員後,如何重定向回帳戶頁面?重定向到另一個控制器中的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