title: Rails 4: composed_of mapping to JSON store attribute
body: <p>I have the following models set up</p>
  
  <pre><code># task.rb
  class Task &lt;&lt; AR
    # everything all task objects have in common
  end
  
  # login_request.rb
  class Tasks::LoginRequest &lt; Task
    store :data, accessors: [:email, :first_name, :last_name, :expires_at]
  
    composed_of :valid_until, class_name: 'DateTime', mapping: %w(expires_at to_s), constructor: Proc.new { |date| (date &amp;&amp; date.to_datetime) || DateTime.now }, converter: Proc.new { |value| value.to_s.to_datetime }
  end
  </code></pre>
  
  <p>I'm using the <code>datetime_select</code> helper in my form:</p>
  
  <pre><code># _form.html.haml
  = f.datetime_select :valid_until
  </code></pre>
  
  <p>This works quite well, but when I call <code>update</code> in my controller with the submitted form data I get the following error message:</p>
  
  <pre><code>1 error(s) on assignment of multiparameter attributes [error on assignment [2014, 4, 2, 9, 48] to valid_until (can't write unknown attribute 'expires_at')]
  </code></pre>
  
  <p>So, I'm guessing the updated method tries to manipulate the <code>attributes</code> hash directly, but obviously it can't find the attribute <code>expires_at</code>, since it's a simple accessor method of the JSON column <code>data</code>.</p>
  
  <p>I know I could simply add this field to the DB and it would probably work - although there's no need then to have a <code>composed_of</code> statement. But I'd rather not go this route, because not every task has a <code>expires_at</code> column.</p>
  
  <p>How can I overcome this error? Or did I miss something?</p>