0

基本上我有一个下拉菜单,旨在通过调用控制器中的方法来启动部分。部分如下图:

<%= form_for :exam_report, :url=>{:action=>'generated_report'} do |z| %>

<%= select_tag :exam_report_batch, 
options_for_select(
Batch.find(:all,:select=>"name,id").collect{|c| [c.name,c.id]}),
:data => { :remote => true, :url => url_for(:controller => "exam", 
                                 :action => "list_exam_types",
                                 :prompt =>"Select a batch")} %>


 <div id="exam-group-select">
 <%= select :exam_report, :exam_group_id, @exam_groups.map{|exam| [exam.name,exam.id]},:prompt=> "#{t('select_exam_group')}" %>
</div>

 <%= z.submit "View", class: "btn btn-large btn-primary" %>

 <% end %>

Exam 控制器中的“list_exam_types”方法如下所示:

def list_exam_types
batch = Batch.find(params[:batch_id])
@exam_groups = ExamGroup.find_all_by_batch_id(batch.id)
respond_to do |format|
   format.html
   format.js   
end
end

因此,当我从下拉列表中选择批次时,出现以下错误:ActiveRecord::RecordNotFound (Couldn't find Batch without an ID): app/controllers/exam_controller.rb:224:in `list_exam_types'

我的路线如下所示:

resources :batches do
resources :exam_groups
resources :additional_exam_groups
resources :elective_groups
end 

resources :exam_groups do
resources :exams do
  member do
    post :save_scores
  end
end
end

我想我的路线很好,所以我不知道为什么 params[:batch_id] 是空的。非常感谢您的帮助,谢谢!

4

0 回答 0