def new @event_selected = Event.find(params[:event_select ])Parameters: {"utf8"=>"✓", "authenticity_token"=>"GMMg9DwnTRAw4qP/ICqgACUB4d42Pl9Y7hrrNQzO38K8inbgyM00H2etrepjrT35hwIenHfwQPQW08V6QnHl1A==" , "event_selected"=>"14",On Tuesday, October 13, 2015 at 2:46:28 PM UTC-6, Prkl8r wrote:
I am trying to pass parameters from an "Events" controller, to an "Invitations" controller and from the Invitations#new to the Invitations#create views. I think I'm pretty close to getting this wrapped up bit keep getting: "param is missing or the value is empty: " errors when I run it.
In order to pass the event.id from the Event#show view I am doing the following through the "Invite Guests" link.
events/show.html.erb
<% @user.owned_events.each do |e| %> <ul> <li><%= e.name %> | <%= link_to "Invite Guests", invitations_new_path(:event_select => e.id) %></li>
That should pass the current event selected as event_select.
I am then using that event id as well as all of the user ids(minus the current_user) to create a list of possible invitees.
invitations_controller.rb:
class InvitationsController < ApplicationController helper_method :current_user def new @event_selected = Event.find(params[:event_select ]) @users = User.where("id != ?", current_user.id ) end def create @invitation = Invitation.new(invite_params) end private def invite_params params.require(:attended_event_id => params[:event_selected], :attendee_id => params[:user_ids].first ) end end
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 %> </li> <% end %> </ul> <br> <%= submit_tag "Invite Selected Users" %> <% end %>
I am trying to get this to work to select just a single user at a time before moving to create multiple objects from the selected event combined with all the results in the user_id array. When I select a single user I keep getting the missing param error but looking at the hash, it seems like everything is there.
param is missing or the value is empty: {:attended_event_id=>"14", :attendee_id=>"3"} Parameters: {"utf8"=>"✓", "authenticity_token"=>"GMMg9DwnTRAw4qP/ , "event_selected"=>"14", "user_ids"=>["3"], "commit"=>"Invite Selected Users"}ICqgACUB4d42Pl9Y7hrrNQzO38K8in bgyM00H2etrepjrT35hwIenHfwQPQW 08V6QnHl1A=="
Pretty new at this coding thing but this is the first problem I haven't been able to solve through a lot stackoverflow searches. I seem to be missing something here and I'm sure it's just a simple thing. Then again I could be completely missing the mark trying to go about this without following a bit more guided path...
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/4fa4bb53-8664-4d14-a265-14adc9216554%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment