I'm having issues with nested attributes and Devise. A similar problem with How to use nested attributes using a development model . As far as I can tell, I have everything that was recommended here: Override version registration controller
I set up associations for users and subscribers, I have "accepts_nested_attributes_for" and included :subscriptions_attributes in attr_accessible , but I get a warning from the Devise controller.
class User < 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
-
class Subscription < 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
devise / registrations / new.html.erb:
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> <p><%= f.label :first_name %><br /> <%= f.text_field :first_name %></p> ... <%= f.fields_for :subscription do |s| %> <p><%= s.label :chargify_subscription_id %><br /> <%= s.text_field :chargify_subscription_id %></p> ...
I get the following warning:
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"=>"Sign up", "authenticity_token"=>"wNZhZgIhYm9CpZfhvDiRBqaJseoO8QvR0Mk9VIybhcI=", "utf8"=>"✓", "user"=>{"password_confirmation"=>"[FILTERED]", "last_name"=>"9", "subscription"=>{"chargify_product_handle"=>"medium", "chargify_subscription_id"=>"123"}, "password"=>"[FILTERED]", "first_name"=>"9", "email"=>" 99@99. com"}} WARNING: Can't mass-assign protected attributes: subscription
I tried using subscription_attributes (single) in attr_accessible , but this does not work.
Any suggestions on what I might be doing wrong? Thanks.