开发者

create function in controller not saving two separate params

these are the codes

<p>
<% form_for @movie do |m| %>
<%= m.label :title, 'Title' %>:
<%= m.text_field :title %></br>
<%= m.label :release_year, 'Release Year' %>:
<%= m.select :release_year, (1900..开发者_高级运维2011) %></br>
</br>

<% Movie.genres.each do |genre| %>
    <%=h genre %>
    <%= check_box_tag :genre, genre %></br>
<% end%>
</br>

<%= m.submit "Save" %>

<% end %>
</p>

and my code in the controller:

def create
@movie = Movie.new(params[:movie].merge(:genre))
if @movie.save!
  render show_path
else
  render new_path
end

But for whatever reason, I keep getting error messages saying "undefined method `each_pair' for :genre:Symbol" or "cannot find Movie without an ID". It's not saving properly.

Is it because of my submit form is only the movie form |m| or is it because my create function in the controller is wrong?

Thanks.


perhaps instead of

params[:movie].merge(:genre)

you wanted to do

params[:movie].merge(:genre => params[:genre])

?


Check Firebug in Firefox (or the Chrome developer tools if you're using Chrome, or your app logs if you're using neither), and see what parameters are actually being passed in your scenario? Sounds like your code is expecting to receive a parameter that is not actually being passed. The tools/log should reveal where the breakdown is happening.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜