'id'= (ActiveRecord :: RecordNotFound) 인 컨테스트를 찾을 수 없습니다.

2017-11-11 10 views
0

Ruby on Rails를 사용하는 웹 앱을 만들고 있습니다. 나는 "id = '(ActiveRecord :: RecordNotFound)"게시물을 찾을 수는 없었지만 그 중 아무 것도 내 문제를 해결하지 못했습니다.'id'= (ActiveRecord :: RecordNotFound) 인 컨테스트를 찾을 수 없습니다.

나는 race_id 매개 변수를 사용하여 전달하는 HAML보기가 있습니다.

= form_tag weigh_ins_path, :method => :post, :id => 'select_weigh_in_form' do 

    = label :weigh_in, :competition_id, 'Competition' 
    = select :weigh_in, :competition_id, options_from_collection_for_select(@competitions, 'id', 'name'), :include_blank => true 

    = submit_tag 'Select Competition & Week' 

내가 그런 존재하지 않거나 null가 아닌 competitions_id 또는 아무것도를 포함하여, 다음과 같은 매개 변수를 사용하여 요청이 있습니다

:

{"utf8"=>"✓", 
"authenticity_token"=>"***Some stuff***==", 
"weigh_in"=>{"competition_id"=>"1"}, 
"commit"=>"Select Competition & Week"} 

나는 competition_id 매개 변수를 예상하는 컨트롤러가

def create 
    @competition = Competition.find params[:competition_id] 
    ***some more stuff** 

하지만 오이로 테스트하면이 오류가 발생합니다.

,210

내가 웹 응용 프로그램 사용하려고 할 때이 오류가 발생합니다 :

ActiveRecord::RecordNotFound in WeighInsController#create 
Couldn't find Competition with 'id'= 

그래서 뷰에서 POST 요청이 매개 변수를 보내는 경우에도를, 컨트롤러를 받고되지 않는 이유는 무엇입니까? 이 문제를 어떻게 해결할 수 있습니까?

답변

1

질문에 게시 된 요청에 competition_id이 (과) 중첩되어 있습니다. 다음과 같이 매개 변수에서 검색해보십시오.

params[:weigh_in][:competition_id] 
+0

고마워요! 나는 그것을 그런 식으로 디자인하려고하지 않았기 때문에 중첩 된 것을 인식하지 못했습니다. – alternum5

 관련 문제

  • 관련 문제 없음^_^