[英]how can I display controller's variable (which is on a loop) on .html.erb page? ruby on rails
I have the following code listed below in my controller: 我的控制器中列出了以下代码:
struc = {'en' => 'english', 'es' => 'espaniol', 'de' => 'germany', 'fr' => 'french', 'it' => 'italy'}
struc.each_pair do |key, value|
@key=key
@value=value
end
on my application.html.erb I have the following 在我的application.html.erb上,我有以下内容
<select name="Language" onchange="location=this.options[this.selectedIndex].value;">
<option value="/<% @key %>/<%= @rem %>"><%= @value %></option>
</select>
Now how can i make the value of '@key' and '@value' appear recursively display on (application.html.erb)? 现在如何让(@key)和'@value'的值递归显示在(application.html.erb)上?
Also How can I change its styling ie make the value appear smaller, tucked in nicely?? 另外,如何更改样式,即使值看起来更小,隐藏得更好?
Thanks in advance 提前致谢
Why not something like 为什么不这样
in controller
@langs = { :en => 'english',
:es => 'espaniol',
:de => 'germany',
:fr => 'french',
:it => 'italy' }
in view
<select name="language" onChange="location = this.options[this.selectedIndex].value;">
<% @langs.each_pair do |short, long| %>
<option value="<%= short %>"><%= long %></option>
<% end %>
</select>
You will need to make struc available to the view by turning it into an instance variable - ie, @struc. 您需要通过将struc转换为实例变量-即@struc,使该视图可用。 Then in your view do 然后在您看来
<select name="Language" onchange="location=this.options[this.selectedIndex].value;">
<% @struc.each_pair do |key, value| %>
<option value="/<%= key %>/<%= @rem %>"><%= value %></option>
<% end %>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.