LoginSignup
5
5

More than 5 years have passed since last update.

rails select_tagのvalueを変えて送信

Last updated at Posted at 2017-03-19

railsのform_tagの中にプルダウンメニューを追加します。

<%= select_tag 'range', options_for_select([["300","1"], ["500","2"], ["1000","3"], ["2000","4"], ["3000","5"]],:selected=>"5") %>

結果

<select name="range" id="range">
<option value="1">300</option>
<option value="2">500</option>
<option value="3">1000</option>
<option value="4">2000</option>
<option selected="selected" value="5">3000</option></select>

こんな感じになります。(bootstrap)
スクリーンショット 2017-03-19 9.09.35.png

submitされたrangeをControllerで取得してHTML

#controller
@range = params[:range]

#View
<%=@range%>

この場合 5 と表示されます。

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5