メールボックス システムのビューを実装しています。受信ボックスと送信済みメールボックスが必要です。したがって、次のような 2 つのリンクをビューに配置します。
<%= 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
ます。推奨される場所はどこですか?