0

I have an event with many guests for that event. A guest must search themselves using their ID to RSVP but I cannot get the search to return that guests info (show/edit page).

The search tag:

<div>
  <h3>Enter your ID here:</h3>
  <%= form_for "", url: event_guest_path(@event,@guest), role: 'search', method: :get do %>
  <%= text_field_tag :search, @search_term, placeholder: "Search.." %>
  <% end %>
</div>

GuestController:

def show
    if params[:search]
      @search_term = params[:search]
      @guest = @event.guests.search_by(@search_term)
    end
  end

Guest.rb:

 def self.search_by(search_term)
    where("(id) LIKE :search_term", search_term: "%#{search_term}%")
  end

At the moment it keeps taking me to the index page but I want it to return the guest path where they can make their RSVP.

  • I don't think you want to do a `LIKE` search you should want the exact match for an ID. For example if you'd put in just one number or one letter it would find all of the guests just with that one character in their ID so they could RSVP as someone else. – edariedl Aug 10 '19 at 11:36
  • This sounds more like something that should be solved by sending the invited guests a link containing a token. – max Aug 11 '19 at 20:37

1 Answers1

0

We should have a more precision to clearly answer you. Because your query like a bit overkill.

A guest have a unique ID for a specific event ?

If that is the case I suggest you to simply use the following code in your show:

Guest.find_by(search_term: params[:search])

If your Guest has a unique ID which can be used for multiple event you probably want to create a join table but I am speculating.

morissetcl
  • 544
  • 3
  • 10