I've got the following route defined:
get 'invites/search', to: 'invites#edit', controller: :invites
Which I changed from:
get 'invites/search', to: 'invites#show', controller: :invites
The controller is as follows:
def show
@invite = Invite.find(params[:id])
end
...
def edit
# If the request is a search containing an 'invite_code'
if params.has_key?(:invite_code)
@invite = Invite.where(invite_code: params[:invite_code]).first
else
@invite = Invite.find(params[:id])
end
end
I get the following error:
ActiveRecord::RecordNotFound in InvitesController#show
Couldn't find Invite with 'id'=search
Extracted source (around line #7):
6 def show
7 @invite = Invite.find(params[:id])
8 end
def new
Which suggests the route hasn't updated?
Here's the rake route:
invites_search GET /invites/search(.:format) invites#edit
I've tried restarting the server, but I'm not really sure what to do now? How can I get the route to go to 'edit' not 'show'?
Thanks,
LM.
EDIT:
Here's the form from the index page:
<%= form_tag invites_search_path, method: :get do %>
<%= label_tag :invite_code, "#" %>
<%= text_field_tag :invite_code, nil %>
<%= submit_tag "Search", name: nil %>
<% end %>
EDIT 2:
See here for the explantion of what I'm trying to achieve with this code: Ruby on Rails: Find a record by an attribute not an id