开发者

ActiveRecord::RecordNotFound (Couldn't find Species without an ID)

I'm trying to learn some Rails but I seem to get stuck on this basic task.

In my "Catch" create form I use a dropdown list to connect a catch to a specie. It renders fi开发者_StackOverflowne:

<select id="catch_species_id" name="catch[species_id]">  
<option value="">Please >select</option>  
<option value="1">A species</option>  
</select>

And the helper I use is

<%= collection_select(:catch, :species_id, @species, 
      :id, :name, {:prompt => true}) %>

But when I try to create a "catch" I get the error:

Parameters: {"utf8"=>"✓",
   "authenticity_token"=>"tfS0WZGGZABBOk9UbPbAvnU3iCqXLvDODivL3+Jr7Io=", 
   "catch"=>{"length"=>"55", "weight"=>"66", **"species_id"=>"1"**}, 
   "commit"=>"Create Catch"}

ActiveRecord::RecordNotFound (Couldn't find Species without an ID):

Species with ID 1 exists but my controller doesn't seem to find it or the param, it feels right but it will not work.

def create  
   @species = Species.find(params[:species_id])  
   @catch = @species.catches.create(params[:catch])  
   redirect_to species_path(@species)  
end


It should be like as follows:-

@species = Species.find(params[:catch][:species_id])

Thanks, Anubhaw

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜