I’m seeing a lot of stuff about saving with nested forms, but all of them have the opposite relationship than mine. Customer Info belongs_to User, but I want to update the user email from Customer Info. Right now the view is working, it’s just not saving.
I have the following relationships defined:
class User < ActiveRecord::Base
has_one :customer_info, dependent: :destroy
accepts_nested_attributes_for :customer_info
end
class CustomerInfo < ActiveRecord::Base
belongs_to :user
attr_accessible :user, :email
accepts_nested_attributes_for :user
end
And the following nested form:
%h1 Editing customer_info
= form_for @customer_info, :validate => true do |f|
- if @customer_info.errors.any?
#error_explanation
%h2= "#{pluralize(@customer_info.errors.count, "error")} prohibited this user from being saved:"
%ul
- @customer_info.errors.full_messages.each do |msg|
%li= msg
%h2 Your Profile
= fields_for @user do |i|
.field
= i.label :email, 'Email'
= i.text_field :email
.field
= f.label :username, "Username"
= f.text_field :username
.actions
= f.submit 'Next'
Turns out it actually was saving through something I did along the way, I was just using devise, so it wasn’t letting me just change the email in the database, I had to confirm.
Thanks to Ahmad for encouraging me to CHECK OUT THE CONSOLE to get a better idea of what was happening.