如何“保存”特色文字?

时间:2016-02-11 22:10:03

标签: ruby-on-rails ruby text save

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

视图/挑战/ _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 %>

enter image description here

1 个答案:

答案 0 :(得分:1)

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

同时使用simple_formhttps://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 %>