I am trying to create a form that displays multiple options of how to display data on a map based on different spans of time (day of week, time of day...). I would like to save the options the user inputs from the form using Ruby on Rails but am unaware of how to create a form using the select tag. I have the code in html as of now but would like to convert it into Ruby on Rails so I can abstract the values inputed by the user easily in order to display the correct data. This is the code I have
<!-- SPAN OF TIME-->
<strong>Span:</strong>
<select id="span" class="span2">
<option>Today</option>
<option>This Week</option>
<option>This Month</option>
<option>This Year</option>
</select>
</br>
<!-- WEEKDAY -->
<strong>Weekday:</strong>
<select id="weekday" class="span2">
<option>All days</option>
<option>Weekend</option>
<option>Weekdays</option>
<option>Sunday</option>
<option>Monday</option>
<option>Tuesday</option>
<option>Wednesday</option>
<option>Thursday</option>
<option>Friday</option>
<option>Saturday</option>
</select>
</br>
<!-- WEEKDAY -->
<strong>Time of Day:</strong>
<select id="time" class="span2">
<option>Morning</option>
<option>Afternoon</option>
<option>Night</option>
</select>
</br>
<button type="submit" class="btn btn-primary">Show Data</button>
Your option tags need to have a value attribute. The option value is what is submitted to the controller. You will then be able to access this data through the params hash. I would also suggest using rails form helpers to generate these tags dynamically.
http://guides.rubyonrails.org/form_helpers.html#the-select-and-option-tags
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.