好的,这是我在点击特定链接时收到的浏览器中显示的一般错误消息:
没有路线匹配{:action =>“edit”,:controller =>“timesheets”,:incident_id => nil}
以下是包含链接的页面的代码(包括创建新记录的路径)
<div style="float:left;padding:25px;">
<p><%= link_to "Add a Command Officer", new_incident_timesheet_command_officer_path %></p>
</div>
在点击链接之前,浏览器网址的内容如下:
本地主机:3000 /事件/ 197 /时间表/编辑
上面的浏览器网址很有意义。
当我将鼠标悬停在“添加指挥官”链接上时,它会在浏览器底部显示: 本地主机:3000 /事件/ 197 /时间表/ command_officers /新
但是当我点击它时,我得到了我在顶部提到的路由错误。以下是Command_Officers_controller和路由文件中的代码。
我相信我已经包含了所有必要的信息,可以帮助我,但如果我遗失了某些内容,请告诉我。谢谢你的帮助
的routes.rb
root :to => "incidents#index"
resources :users
resources :profiles
resources :incidents do
resource :mat_list
member do
post :send_notice
end
member do
get :changestatus
end
resource :timesheet do
resources :command_officers
resources :fire_chiefs
resources :fire_fighters
resources :safety_officers
resources :emts
resources :hazmat_specialists
resources :command_vehicles
resources :engines
resources :emergency_supports
resources :hazmat_units
resources :field_units
resources :pumpers
resources :tankers
resources :rescue_units
resources :ladder_truck75s
resources :ladder_truck150s
end
end
resource :session do
member do
get :resetpass
post :resetpass
end
end
command_officers_controller.rb
def new
@command_officer = CommandOfficer.new
@timesheet = Incident.find(params[:incident_id]).timesheet
respond_to do |format|
format.html # new.html.erb
end
end
# GET /command_officers/1/edit
def edit
@command_officer = CommandOfficer.find(params[:id])
end
# POST /command_officers
# POST /command_officers.xml
def create
# @new_command_officer = CommandOfficer.new(params[:command_officer])
@timesheet = Incident.find(params[:incident_id]).timesheet
@command_officer = @timesheet.command_officer.build(params[:command_officer])
respond_to do |format|
if @command_officer.save
format.html { redirect_to(edit_incident_timesheet_path, :notice => 'Command officer was successfully created.') }
else
flash[:error] = "What happened?"
format.html { render :new }
end
end
end
答案 0 :(得分:1)
您执行了嵌套路由,但没有传递事件ID,如果您有一个名为@incident
的实例变量,您可以这样做:
<%= link_to "Add a Command Officer", new_incident_timesheet_command_officer_path(@incident) %>
答案 1 :(得分:1)
问题是你试图在下一页上生成一些链接,但是你传递给rails的incident_id是零。检查您的视图/控制器并删除/修复有问题的代码。
更一般地说,学习如何阅读rails给你的堆栈跟踪,以便你自己跟踪它们。