如何"Save" 精选文字?

How to "Save" Featured Text?

如果用户点击 featured-challenge 如何将其另存为 :action

views/challenges/_form.html.erb

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

可以构建为单选按钮并传递选定的输入

也可以用 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 %>