title: ActiveModel::MissingAttributeError in rails 4
body: <p>The code in this question works without issue in Rails 3, but it's raising a ActiveModel::MissingAttributeError in rails 4, which also uses Devise (for Rails 4). There are three relevant models, with a polymorphic relationship between the User model and the other two.</p>
  
  <p>User.rb</p>
  
  <pre><code>  belongs_to :profile, polymorphic: true
  </code></pre>
  
  <p>LawyerProfile.rb</p>
  
  <pre><code> has_one :user, as: :profile, dependent: :destroy
  </code></pre>
  
  <p>LawStudentProfile.rb</p>
  
  <pre><code>has_one :user, as: :profile, dependent: :destroy
  </code></pre>
  
  <p>After the user fills out the relevant registration form, a new lawyer or student profile is created for the new user inside the after_sign_up_path_for(user) method from Devise that I've rewritten inside the registrations controller, like this</p>
  
  <pre><code>class RegistrationsController &lt; Devise::RegistrationsController
  
  def after_sign_up_path_for(user)
  
      if user.lawyer === true
  
        user.profile = LawyerProfile.create!
  
        user.add_role :lawyer 
        user.save!
  
      elsif user.student === true
        user.profile = LawStudentProfile.create!
  
        user.add_role :student
         user.save!
  
      else 
      ...
  </code></pre>
  
  <p>I'm getting an error on this line (on a lawyer sign up)</p>
  
  <pre><code> user.profile = LawyerProfile.create!
  </code></pre>
  
  <p>with this error message</p>
  
  <pre><code>ActiveModel::MissingAttributeError in RegistrationsController#create
  
  can't write unknown attribute `profile_id'
  </code></pre>
  
  <p>As I had this working on a Rails 3 app, I'm guessing this might be related to strong parameters, however, I never had to add profile_id to a list of   <code>attr_accessible</code> in the Rails 3 app, so I'm not entirely certain it's a strong parameters issue.In fact, neither the user nor the LawyerProfile model has an attribute (that I created or which is otherwise visible) called profile_id</p>
  
  <p>Anyways, inside the Application controller, per Devise instructions, I added the following which creates the whitelist of accepted parameters for user on signup. I added :profile_id to this list but I still got the same error.</p>
  
  <pre><code>  before_filter :configure_permitted_parameters, if: :devise_controller?
  
    def configure_permitted_parameters
      devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :lawyer, :student, :password) }
    end
  </code></pre>
  
  <p>Not being entirely clear about polymorphic associations, I thought maybe :profile_id is an attribute of LawyerProfile (even though i didn't add it to LawyerProfile.rb  <code>attr_accessible</code> in the Rails 3 app). There is no create action in my lawyer_profiles controller.</p>
  
  <p>Questions</p>
  
  <p>1) if the reason for the error message is that I have not created a whitelist of attributes (i.e. :profile_id) for the LawyerProfile.rb model, how do I do that in the lawyer_profiles_controller if I don't have a create action? I only use LawyerProfile.create! the one time. </p>
  
  <p>2) what might be another reason for this error if it's not the reason alluded to in the first question?</p>
  
  <p>Update,
  One odd aspect of this is that neither the User model nor the LawyerProfile model have a <code>profile_id</code> column. They both just have id columns, as was the case in the Rails 3 version.</p>