Note that there are some explanatory texts on larger screens.

plurals
  1. PORails nested model type mismatch
    primarykey
    data
    text
    <p>I have an app which runs without any problems on my development machine. When I push it to Heroku, I get the following error which causes the app to crash:</p> <pre><code>ActiveRecord::AssociationTypeMismatch (Profile(#47183120) expected, got ActiveSupport::HashWithIndifferentAccess(#35109340)) </code></pre> <p>From the logs, this is:</p> <pre><code>153 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - Started POST "/users" for 2.124.94.147/027c5e93.bb.sky.com at 2012-06-04 00:07:57 +0000 138 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - Processing by RegistrationsController#create as HTML 517 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"ztrHyRb/VzLSNRKZI1ifP6NZfdXFacDGi6edxM7RCRM=", "user"=&gt;{"email"=&gt;"user@email.com", "username"=&gt;"user", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]", "profile"=&gt;{"full_name"=&gt;"Some Name", "birth_date(3i)"=&gt;"21", "birth_date(2i)"=&gt;"10", "birth_date(1i)"=&gt;"1985", "gender"=&gt;"0", "postcode"=&gt;"XXXX XXX", "description"=&gt;"Site designer."}}, "commit"=&gt;"Sign up"} 129 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - Completed 500 Internal Server Error in 84ms 86 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - 211 &lt;13&gt;1 2012-06-04T00:07:57+00:00 app web.1 - - ActiveRecord::AssociationTypeMismatch (Profile(#47001900) expected, got ActiveSupport::HashWithIndifferentAccess(#29446440)): </code></pre> <p>User model (from Devise):</p> <pre><code>class User &lt; ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # FriendlyID for slugs extend FriendlyId friendly_id :username, use: :slugged # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :profile_attributes, :remember_me, :username # attr_accessible :title, :body # Set relationships has_one :profile, dependent: :destroy accepts_nested_attributes_for :profile # Validation VALID_USERNAME_REGEX = /^[a-z0-9_]+$/i validates :username, presence: true, uniqueness: true, length: { minimum: 5, maximum: 15 }, format: { with: VALID_USERNAME_REGEX } end </code></pre> <p>Profile model:</p> <pre><code>class Profile &lt; ActiveRecord::Base attr_accessible :birth_date, :description, :full_name, :gender, :latitude, :longitude, :postcode belongs_to :user geocoded_by :geocode_string INVALID_NAME_REGEX = /^[^0-9`!@#\$%\^&amp;*+_=]+$/ VALID_POSTCODE_REGEX = /^\s*((GIR\s*0AA)|((([A-PR-UWYZ][0-9]{1,2})|(([A-PR-UWYZ][A-HK-Y][0-9]{1,2})|(([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))))\s*[0-9][ABD-HJLNP-UW-Z]{2}))\s*$/i validates :full_name, format: { with: INVALID_NAME_REGEX }, presence: true validates :birth_date, timeliness: { before: :today, type: :date }, presence: true validates :gender, presence: true validates :postcode, format: { with: VALID_POSTCODE_REGEX }, allow_blank: true validates :description, length: { maximum: 500 } after_validation :geocode private def geocode_string "#{postcode}" end end </code></pre> <p>New user view (users/registrations):</p> <pre><code>&lt;h2&gt;Sign up&lt;/h2&gt; &lt;% resource.build_profile %&gt; &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;div&gt;&lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.email_field :email %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :username %&gt; &lt;i&gt;(this cannot be changed so choose wisely)&lt;/i&gt;&lt;br /&gt; &lt;%= f.text_field :username %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :password %&gt;&lt;br /&gt; &lt;%= f.password_field :password %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt; &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt; &lt;%= f.fields_for resource.profile do |profile_form| %&gt; &lt;div&gt;&lt;%= profile_form.label :full_name %&gt;&lt;br /&gt; &lt;%= profile_form.text_field :full_name %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= profile_form.label :birth_date %&gt;&lt;br /&gt; &lt;%= profile_form.date_select :birth_date, start_year: Time.now.year, end_year: Time.now.year - 80, order: [:day, :month, :year], prompt: { day: 'Choose day', month: 'Choose month', year: 'Choose year' } %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= profile_form.label :gender %&gt;&lt;br /&gt; &lt;%= profile_form.select :gender, { "Male" =&gt; '0', "Female" =&gt; '1' } %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= profile_form.label :postcode %&gt;&lt;br /&gt; &lt;%= profile_form.text_field :postcode %&gt;&lt;/div&gt; &lt;div&gt;&lt;%= profile_form.label :description, "About you" %&gt;&lt;br /&gt; &lt;%= profile_form.text_area :description %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;div&gt;&lt;%= f.submit "Sign up" %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;%= render :partial =&gt; "devise/shared/links" %&gt; </code></pre> <p>The registrations controller is, for all intents and purposes, standard apart from changing the after_update_path:</p> <pre><code>class RegistrationsController &lt; Devise::RegistrationsController protected def after_update_path_for(resource) users_control_panel_path end end </code></pre> <p>I have seen some other posts about this but they don't seem to be relevant - forgive me if I am wrong. What is the problem and how do I resolve it? I'm particularly confused because this runs on my local machine but not on Heroku (I have migrated the database).</p> <p><strong>Edit:</strong></p> <p>Apologies, it doesn't work on my development machine - I added this functionality in, it didn't work, so I added the details in the console instead and forgot to revisit it.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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