Biju
Biju

Reputation: 978

How to pass parameters in routes.rb in rails?

get 'show_category', to: 'movies#show_category', as: 'show_category'

I have the above routes entry.

I use this code in my view:

<% @categories.each do |category| %>
  <tr><td>

    <%= link_to category, show_category_url, :genre => category, :remote => true %> <%end%>

  </td></tr>
<% end %>

As shown above, I would like to pass a parameter named genre and pass the value of category into that parameter. But when I try to print the value of the parameter inside the target function in my controller, I don't get ay value there:

def show_category
  puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  puts params[:genre]
end

What am I doing wrong here?

Upvotes: 0

Views: 228

Answers (1)

Vasilisa
Vasilisa

Reputation: 4640

Pass parameters in brackets

show_category_url(genre: category)

Upvotes: 1

Related Questions