Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Approach 1 (Hacky):</strong></p> <p>What you're asking is multi-parameter assignment which is done by <a href="http://apidock.com/rails/ActiveRecord/AttributeAssignment/assign_multiparameter_attributes" rel="nofollow">assign_multiparameter_attributes</a>. </p> <p>Change your form to look similar to this.</p> <pre><code>= select_day @user.birthdate, prefix: "user", field_name: "birthdate(3i)" = select_month @user.birthdate, prefix: "user", field_name: "birthdate(2i)" = select_year @user.birthdate, prefix: "user", field_name: "birthdate(1i)" </code></pre> <p><code>assign_multiparameter_attributes</code> expects the column type to be known to set the value. For that to work, you will have to have a method called <code>column_for_attribute(name)</code></p> <pre><code>attr_accessor :birthdate def column_for_attribute(name) return ActiveRecord::ConnectionAdapters::Column.new(:birthdate, nil, "date") if name.to_sym == :birthdate end </code></pre> <p>This is why using <code>ActiveRecord</code> modules without DB is a bad idea.</p> <p><strong>Approach 2 (Enhance ActiveModel):</strong></p> <p>Have a look at <a href="https://coderwall.com/p/eqwiqg" rel="nofollow">this</a>. It attempts to create an <code>BaseModel</code> which handles assigning dates.</p> <p><strong>Approach 3 (Custom code):</strong></p> <p>If you don't wanna use the gem, then the way would be to introduce three attributes <code>(day, month, year)</code> in <code>User</code> and have a method called <code>birthdate</code> which creates <code>Date</code> object from those three.</p> <p>If you have similar requirements at many places, I would suggest to enhance ActiveModel (Approach 2). But If you've this requirement at only one place go with Approach 3.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload