Simple_form input with multiple fields

I'm not quite sure what the correct terms are, but what I'm trying to do in the form (preferably using simple_form pearls) has one of the inputs: maximum, use a text box and select a box. The user enters a text field into a number, and then selects the hours, days, or months from the drop-down list. Thus, 21 days, 3 months, 3 hours, etc. When the form was submitted, I convert it to days and save it in the database. I know how to change the input type in simple_form, but is it possible to have two inputs for one variable?

+5
source share
1 answer

Of course :) Here is my idea:

:

attr_accessor :thing, :another_thing, :and_another_thing

, , "" form_for helper, , :

<%= form.input :thing, :as => :boolean %>
<%= form.input :another_thing, :as => :text %>

... . (: formtastic. Rails, formtastic gem.)

, :

before_create :build_my_fancy_record

def build_my_fancy_record
  self.storage_field = "#{thing} #{another_thing}"
end
+4

All Articles