1

RubyonRailsは初めてです。ページのリロードでドロップダウンとチェックされたラジオボタンから選択した値を表示したいと思います。ページがリロードされると、ドロップダウンとラジオボタンの選択された値がリセットされます。この問題を修正する方法を教えてください。使用しているコードは次のとおりです。

    <%= 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 に答える