dimanche 31 janvier 2016

Rails - passing extra parameters through a link

I have two tables in my application. The user table and the activities - the user has many activities (3 in total to be exact).

I have a home page with 3 buttons on it. If the user presses button one, I want to navigate to the activities index page and set the attribute activity_type to = 1. If the user presses button 2, I want to navigate to the activities index page and set the activity_type to = 2 etc. Right now I have:

<%= link_to 'Personal Activity', user_activities_path(:user_id => current_user.id, :activity_type => 1) %>
<%= link_to 'Physical Activity', user_activities_path(:user_id => current_user.id, :activity_type => 2) %>
<%= link_to 'Community Activity', user_activities_path(:user_id => current_user.id, :activity_type => 3) %>

In my activities/index.html.erb file I want to have three conditions:

If the activity_type = 1 for current_user
  Do X
Elsif the activity_type = 2 for current_user
  Do Y
Else
  Do X
End

It doesn't seem to be recognising the activity_type parameter I have included in the link. How do I do this?

Aucun commentaire:

Enregistrer un commentaire