Open hirolibe opened 1 month ago
◯概要 ?locale=jaというクエリパラメータがある場合、通常はこれを無視してパスの一致を確認します。つまり、current_page?()はデフォルトでクエリパラメータを無視します。
◯コード例
app/views/commons/_tabs.html.haml
.tabs .tabs_item{class: "#{add_active_class(root_path)}"} = link_to '新着記事一覧', root_path .tabs_item{class: "#{add_active_class(timeline_path)}"} = link_to 'タイムライン', timeline_path
app/helpers/tabs_helper.rb
module TabsHelper def add_active_class(path) path = path.split('?').first 'active' if current_page?(path) end end
◯概要 ?locale=jaというクエリパラメータがある場合、通常はこれを無視してパスの一致を確認します。つまり、current_page?()はデフォルトでクエリパラメータを無視します。
◯コード例
app/views/commons/_tabs.html.haml
app/helpers/tabs_helper.rb