2

I'm using the Rails gem active_link_to for determining the active URL for menus. It works great on straight forward links such as '/controller/action' but how can I do it similarly for particular param?

Ie /controller/action?user=all

Or is there a better gem that can provide this?

https://github.com/twg/active_link_to

4

1 回答 1

1

您可以使用 gem 的 Regex 功能,具体取决于您的代码的组织方式。

<%= active_link_to("Link Text", some_place_path, :active => /#{Regexp.escape(@param_value)}/, class: "blogYear") %>

如果要动态输出参数或参数值,则可以使用上述方法在正则表达式中执行代码。

于 2013-01-21T19:15:34.650 回答