如果用户点击featured-challenge
,如何将其保存为:action
?
<%= f.text_field :action, placeholder: 'Enter a Custom Challenge' %>
Or choose a featured challenge:
<div class="featured-challenge">Lose 10 Pounds</div>
<div class="featured-challenge">Exercise</div>
<div class="featured-challenge">Quit Smoking</div>
<div class="featured-challenge">Run a 5K</div>
<div class="featured-challenge">Meditate</div>
<div class="featured-challenge">Visit Rome</div>
<div class="featured-challenge">Read a Chapter</div>
<div class="featured-challenge">Walk 10,000 Steps</div>
<div class="featured-challenge">Study a Foriegn Language</div>
<%= f.submit %>
答案 0 :(得分:1)
可以构建为单选按钮并传递所选输入
同时使用simple_form
(https://github.com/plataformatec/simple_form)进行猜测可能会对以下内容产生影响:
<%= simple_form_for @challenge do |f| %>
<%= f.input :custom, placeholder: 'Enter a Custom Challenge' %>
Or choose a featured challenge:
<%= f.input :preset, collection: ['Lose 10 Pounds', 'Exercise', [...]], as: :radio_buttons, input_html: { class: 'featured-challenge' } %>
<%= f.button :submit %>
<% end %>