I have a routes question concerning Rails 5. I have this in my config/routes.rb file
resources :votes
The "show" method in my VotesController can take an ID of either a numeric or string form.
def show
id = params[:id]
if id.present?
# If they entered a name
if id.to_i == 0
name = id.gsub "_", " "
@person = Person.find_by_name(name)
else
@person = Person.find_by_id(id)
end
I used to be able to construct this link_to to link to the method to generate a link with a numeric ID ...
<%= link_to person.name, vote_path(person), :class => 'unvotedPersonLink' %>
However, I would like to generate a link with a string value for the ID, as defined by a method in my model called "person.seo_name". So I tried this
<%= link_to person.name, vote_path(:id => person.seo_name), :class => 'unvotedPersonLink' %>
but got the error
No route matches {:action=>"show", :controller=>"votes", :id=>nil} missing required keys: [:id]
How can I build my link_to tag so that it passes in my desired "string" parameter instead of a numeric one?