我正在实现邮箱系统的视图。我想要收件箱和已发送邮箱。因此,我在视图中放置了两个链接,例如:
<%= link_to "Inbox", messages_user_path(current_user),:class =>"current", :which_mailbox => "received" %>
<%= link_to "Sentbox", messages_user_path(current_user),:class =>"current", :which_mailbox => "sent" %>
然后我希望我的控制器根据 `params[:which_mailbox] 获取适当的消息。如:
def fetch_messages
if params[:which_mailbox] == "received"
@messages= current_user.received_messages
else if params[:which_mailbox] == "sent"
@messages = current_user.sent_messages
end
render 'users/messages_page'
end
与其他选项相比,我想使用粗体字体设置所选邮箱的样式(即 `class="current")。
a .current{
font-weight: bold;
}
问题是这两个选项(收件箱/发送箱)都class="current"
使用了link_to ..
上面的代码。如何激活/停用该课程?没有Javascript可以吗?那只是使用 Rails+ CSS?
编辑 这是生成的 HTML:
<section>
<a href="/users/1/messages" class="current" which_mailbox="received">Inbox</a>
</section>
<section>
<a href="/users/1/messages" class="current" which_mailbox="sent">Sent</a>
</section>
我现在意识到没有params[:which_mailbox]
,我想我应该初始化密钥which_mailbox
,推荐的地方在哪里?