Ruby on rails 在RubyonRails上用IF子句实现下面列出的Select语言?
有谁能帮我在RubyonRails上为不同的页面实现下面的代码吗?例如,下面的代码将其更改为“faq.html.erb”,但只有在它通过If条件之后Ruby on rails 在RubyonRails上用IF子句实现下面列出的Select语言?,ruby-on-rails,ruby,select,locale,Ruby On Rails,Ruby,Select,Locale,有谁能帮我在RubyonRails上为不同的页面实现下面的代码吗?例如,下面的代码将其更改为“faq.html.erb”,但只有在它通过If条件之后 <% if pageName=='faq.html.erb' %> <select name="Language" onchange="location=this.options[this.selectedIndex].value;"> <option value="/en/faq" selec
<% 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 %>
英语
西班牙人
提前谢谢 例如,您可以使用controller\u name或request.path
if request.path =~ /faq/
# ...
elsif controller_name =~ /categories/
# ...
elsif controller_name =~ /categories/ and controller.action_name == 'index'
# ...
谢谢你的回答,每条语句上都会有重复的代码,有没有其他方法可以动态编码而不是硬编码?Meduza的答案有什么不是动态的?他们只是给你一些例子,你不必使用所有的代码。