Ruby on Rails
Wednesday, October 14, 2015
On Tuesday, October 13, 2015 at 9:46:28 PM UTC+1, Prkl8r wrote:
def invite_params params.require(:attended_event_id => params[:event_selected], :attendee_id => params[:user_ids].first ) end
This is completely wrong. This usually looks something like
params.require(:invitation).permit(:attended_event_id, :attendee_id)
which says that the params hash should contain an element for the key :invitation, and that the two named parameters are allowed to be present. (A more elaborate syntax allows for array and hash values - lookup the docs for 'strong parameters')
My view showing the list of users and after selecting a checkbox, should pass the event_selected and user_ids.
invitations/new.html.erb
<h3>Invite users to <%= @event_selected.name %></h3> <%= bootstrap_form_for Invitation.new do |f| %> <br> <ul> <% @users.each do |user| %> <li> <%= hidden_field_tag :event_selected, @event_selected.id %> <%= check_box_tag 'user_ids[]', user.id %> <%= h user.name %>
When you use the _tag helpers (as opposed to g.hidden_field, f.check_box), then your parameters aren't nested with invitation hash as mentioned above. You'll also make your life much easier if the input names correspond to the model attribute names (i.e. attended_event_id instead of event_selected). It also seems a bit odd (although probably harmless) that you are repeating the event_selected input.
Fred
-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7eb39388-b132-43f4-8656-3d4d0e2055a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment