【发布时间】:2016-05-09 00:07:28
【问题描述】:
我的应用程序中有两个表。用户表和活动 - 用户有许多活动(确切地说,总共 3 个)。
我有一个主页,上面有 3 个按钮。如果用户按下按钮 1,我想导航到活动索引页面并将属性 activity_type 设置为 = 1。如果用户按下按钮 2,我想导航到活动索引页面并将 activity_type 设置为 = 2 等等。现在我有:
<%= 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) %>
在我的活动/index.html.erb 文件中,我想要三个条件:
If the activity_type = 1 for current_user
Do X
Elsif the activity_type = 2 for current_user
Do Y
Else
Do X
End
它似乎无法识别我在链接中包含的 activity_type 参数。我该怎么做?
【问题讨论】:
-
您是如何尝试获取
activity_type的?喜欢params[:activity_type]? -
现在我的索引视图中有这个: 。我不确定从哪里获取 activity_type 或在哪里使用 params[:activity_type]?
-
这些链接是否导航到索引页面?如果是这样
params[:activity_type]应该可以工作
标签: ruby-on-rails ruby if-statement hyperlink conditional