选定的值将在页面重新加载中重置为ruby on rails

时间:2013-02-28 06:24:05

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我刚接触到rails上的ruby。我想在页面重新加载时从下拉列表和选中的单选按钮显示所选值。  当重新加载页面时,下拉和单选按钮的选定值将被重置。所以请让我知道如何解决这个问题。这是我使用的代码。

    <%= 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 %>

1 个答案:

答案 0 :(得分: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