1

我是 ruby​​ on rails 的新手。我想显示从下拉菜单中选择的值,并在页面重新加载中选中单选按钮。重新加载页面时,下拉菜单和单选按钮的选定值正在重置。所以请让我知道如何解决此问题。这是我正在使用的代码。

    <%= form_tag :action => 'show' do%>
<strong>Select device: </strong> <%= collection_select(:device, :id, @devices, :id, :name, options ={:prompt => "-Select a device"}) %>
<br></br>
<strong>Chose:</strong><%=  radio_button_tag :name,:time, false, :onclick => "this.parentNode.submit();"%>Time
<%=  radio_button_tag :name,:graph%>Graph
<% end %>
4

1 回答 1

0

尝试:

 collection_select(:device, :id, @devices, :id, :name, {:selected => @your_selected_value, :prompt => "-Select a device"})

参见radio_button_tag(name, value, checked = false, options = {})

<%=  radio_button_tag :name,:time, @your_checked_value.eql?('time'), :onclick => "this.parentNode.submit();"%>Time
<%=  radio_button_tag :name,:graph, @your_checked_value.eql?('graph') %>Graph
于 2013-02-28T06:50:47.350 回答