0

谁能帮我解决如何在 ruby​​ on rails 上为不同页面实现以下代码?例如,下面的代码会将其更改为“faq.html.erb”,但前提是它通过了 If 条件。

<% if pageName=='faq.html.erb' %>
    <select name="Language" onchange="location=this.options[this.selectedIndex].value;">
        <option value="/en/faq" selected="selected">English</option> 
        <option value="/es/faq">Español</option>
    </select>
<% end %>

提前致谢!

4

1 回答 1

1

例如,您可以使用 controller_name 或 request.path。

if request.path =~ /faq/
  # ...
elsif controller_name =~ /categories/
  # ...
elsif controller_name =~ /categories/ and controller.action_name == 'index'
  # ...
于 2012-11-12T15:05:18.183 回答