0

好的,这是我单击特定链接时收到的浏览器中显示的一般错误消息:

没有路线匹配 {: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>

在我单击链接之前,浏览器 url 如下所示:

本地主机:3000/事件/197/时间表/编辑

上面的浏览器 url 完全有意义。

当我将鼠标悬停在“添加指挥官”的链接上时,浏览器底部会显示:localhost:3000/incidents/197/timesheets/command_officers/new

但是当我点击它时,我得到了我在顶部提到的路由错误。这是来自 Command_Officers_controller 和路由文件的代码。

我相信我已经包含了所有必需的信息,以便有人帮助我,但如果我遗漏了什么,请告诉我。谢谢您的帮助

路由.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
4

2 回答 2

1

你做了一个嵌套路由但没有传递事件ID,如果你有一个名为的实例变量@incident,你可以这样做:

<%= link_to "Add a Command Officer", new_incident_timesheet_command_officer_path(@incident) %>
于 2013-03-27T15:28:46.137 回答
1

问题是您正试图在下一页上生成一些链接,但您传递给 rails 的 event_id 为 nil。检查您的视图/控制器并删除/修复有问题的代码。

更一般地说,学习如何阅读 rails 提供的堆栈跟踪信息,以便您自己跟踪这些信息。

于 2013-03-27T15:29:36.243 回答