Note that there are some explanatory texts on larger screens.

plurals
  1. POMass assignment warning when using nested attributes with Devise
    primarykey
    data
    text
    <p>I'm having trouble with nested attributes and Devise. A similar issue to <a href="https://stackoverflow.com/questions/3544265/how-do-i-use-nested-attributes-with-the-devise-model">How do I use nested attributes with the devise model</a>. As far as I can tell I've got everything set up as recommended here: <a href="https://stackoverflow.com/questions/3546289/override-devise-registrations-controller/4527049#4527049">Override devise registrations controller</a></p> <p>I've set up the associations for Users and Subscriptions, I have <code>"accepts_nested_attributes_for"</code>, and included the <code>:subscriptions_attributes</code> in <code>attr_accessible</code>, but I get a warning from the Devise controller.</p> <pre><code>class User &lt; ActiveRecord::Base devise :database_authenticatable, :registerable,:recoverable, :rememberable, :trackable, :validatable validates_presence_of :first_name, :last_name has_many :subscriptions accepts_nested_attributes_for :subscriptions attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :subscriptions_attributes ... end </code></pre> <p>--</p> <pre><code>class Subscription &lt; ActiveRecord::Base belongs_to :user validates_presence_of :user_id, :chargify_subscription_id, :chargify_product_handle attr_accessible :user_id, :chargify_subscription_id, :chargify_product_handle ... end </code></pre> <p>devise/registrations/new.html.erb :</p> <pre><code>&lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;p&gt;&lt;%= f.label :first_name %&gt;&lt;br /&gt; &lt;%= f.text_field :first_name %&gt;&lt;/p&gt; ... &lt;%= f.fields_for :subscription do |s| %&gt; &lt;p&gt;&lt;%= s.label :chargify_subscription_id %&gt;&lt;br /&gt; &lt;%= s.text_field :chargify_subscription_id %&gt;&lt;/p&gt; ... </code></pre> <p>I'm getting the following warning:</p> <pre><code>Started POST "/users" for 127.0.0.1 at Sat May 14 12:38:49 -0700 2011 Processing by Devise::RegistrationsController#create as HTML Parameters: {"commit"=&gt;"Sign up", "authenticity_token"=&gt;"wNZhZgIhYm9CpZfhvDiRBqaJseoO8QvR0Mk9VIybhcI=", "utf8"=&gt;"✓", "user"=&gt;{"password_confirmation"=&gt;"[FILTERED]", "last_name"=&gt;"9", "subscription"=&gt;{"chargify_product_handle"=&gt;"medium", "chargify_subscription_id"=&gt;"123"}, "password"=&gt;"[FILTERED]", "first_name"=&gt;"9", "email"=&gt;"99@99. com"}} WARNING: Can't mass-assign protected attributes: subscription </code></pre> <p>I've tried using <code>subscription_attributes</code> (singular) in <code>attr_accessible</code> but that doesn't work.</p> <p>Any suggestions for what I might be doing wrong? Thanks.</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.
 

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