rails 3编辑表单上的路线问题

时间:2014-11-17 09:06:46

标签: ruby-on-rails ruby-on-rails-3

我有以下路线:

namespace :dashboard do
  resources :kids do
    get   '/sons_report/'                         => 'kids#sons_report',            :as => :sons_report
    get   '/courses/'                             => 'courses#index',               :as => :courses
    post  '/courses/:id'                          => 'courses#show',                :as => :course
    get   '/courses/:id/edit'                     => 'courses#edit',                :as => :edit_course
    put   'courses/:id/update'                    => 'courses#update'
  end
end

在我的编辑视图中,我有以下表格:

= form_tag dashboard_kid_edit_course(@course), :method => 'post', :multipart => true do
  .panel.panel-default
    .panel-heading
      %h1.box-title
        %i.fa.fa-calendar.fa-fw
        Schedule
    .panel-body
      = _('Add a new slot')
      %hr{style: "margin-top:0px;"}
      %table.table.table-bordered
        %thead
          %tr{style: "background-color:#4b3087;color:#fff;text-align:center;"}
            %th Hours
            %th Monday
            %th Tuesday
            %th Wednesday
            %th Thursday
            %th Friday
            %th Saturday
            %th Sunday
        %tbody
          %tr
            %td
              %span.badge.badge-success 8 - 10
            %td
              = check_box_tag 'monday_8-10', 'true', false
            %td
              = check_box_tag 'tuesday_8-10', 'true', false
            %td
              = check_box_tag 'wednesday_8-10', 'true', false
            %td
              = check_box_tag 'thursday_8-10', 'true', false
            %td
              = check_box_tag 'friday_8-10', 'true', false
            %td
              = check_box_tag 'saturday_8-10', 'true', false
            %td
              = check_box_tag 'sunday_8-10', 'true', false
        ...

但是当我尝试编辑课程时出现以下错误:

  

未定义的方法`dashboard_kid_edit_course'对

     

<#:0xa8701d0>

我知道我的表单操作有问题,但我可以找到它,请帮忙。

谢谢

1 个答案:

答案 0 :(得分:0)

查看rake routes的输出。在那里,您可以看到URL前缀为dashboard_kid_edit_course。您还可以看到它需要:kid_id:id(当然)。我想你有一个@kid个实例,所以正确调用帮助应该是这样的:

dashboard_kid_edit_course_path(@kid, @course)