Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9114705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:15:35+00:00 2026-06-17T04:15:35+00:00

I am getting the following error when submitting an update form with nested models

  • 0

I am getting the following error when submitting an update form with nested models in Rails 3.2. Any help with this will be greatly appreciated.

NoMethodError in ProfilesController#update

undefined method `update_attributes' for nil:NilClass
Rails.root: C:/Documents and Settings/Workspace/project_x

Application Trace | Framework Trace | Full Trace
app/controllers/profiles_controller.rb:32:in `update'
Request

Parameters:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"PQFLzhgvFzRyJ2BT/GdIpjRiOM729JoYQUHrZGUi08c=",
 "profile"=>{"addresses_attributes"=>{"0"=>{"address1"=>"588 brodie",
 "address2"=>"Apt1115",
 "city"=>"Austin",
 "state"=>"Alabama",
 "zip"=>"78745",
 "id"=>"1"}},
 "vital_attributes"=>{"birthday(2i)"=>"1",
 "birthday(3i)"=>"11",
 "birthday(1i)"=>"1910",
 "height_feet"=>"3",
 "height_inches"=>"3",
 "weight"=>"220",
 "id"=>"1"},
 "certificate_attributes"=>{"C_ASEL"=>"1",
 "C_AMEL"=>"1",
 "C_ASES"=>"1",
 "C_AMES"=>"0",
 "ATP_ASEL"=>"0",
 "ATP_AMEL"=>"0",
 "ATP_ASES"=>"0",
 "ATP_AMES"=>"0",
 "FI_ASE"=>"1",
 "FI_AME"=>"1",
 "FI_INSTA"=>"1",
 "GI_Basic"=>"0",
 "GI_Advanced"=>"0",
 "GI_Instrument"=>"0",
 "id"=>"1"}},
 "commit"=>"Save & Continue",
 "id"=>"1"}

Here are the models, controller, and form involved:

class Profile < ActiveRecord::Base
   attr_accessible :addresses_attributes, :vital_attributes, :certificate_attributes

   belongs_to :contact
   has_many :addresses
   has_one :certificate
   has_one :vital

   accepts_nested_attributes_for :addresses, :certificate, :vital
end

class Address < ActiveRecord::Base
   belongs_to :profile
end

class Vital < ActiveRecord::Base
   belongs_to :profile
end

class Certificate < ActiveRecord::Base  
   belongs_to :profile  
end


class ProfilesController < ApplicationController

   before_filter :authenticate, :only => [:show, :edit, :update]
   before_filter :correct_contact, :only => [:show, :edit, :update]
.
.
.

def edit
   @profile = Profile.find(params[:id])
   @address = @profile.addresses.first
   @vital = @profile.vital
   @certificate = @profile.certificate
end

def update
   if @profile.update_attributes(params[:profile])
      flash[:success] = "Profile updated"
      render 'edit'
   else
      render 'edit'
   end
end 


private #######################################################################

def authenticate
   deny_access unless signed_in?
end

def correct_contact
   @contact = Contact.find(params[:id])
   redirect_to(root_path) unless current_contact?(@contact)
end

end


<%= form_for @profile, :html => { :class => "form-horizontal" } do |f| %>

<%= f.fields_for :addresses do |aa| %> 
   <%= aa.label :address1, "Address 1:", :class => "control-label" %>
   <%=aa.label :address2, "Address 2:", :class => "control-label" %>
   <%=aa.text_field :address2 %>
   <%= aa.label :city, "City:", :class => "control-label" %>
   <%= aa.text_field :city %>
   <%= aa.label :state, "State:", :class => "control-label" %>
   <%= aa.select(:state, options_for_select([["Alabama", "Alabama"], ["Texas", "Texas"]]), {}, :class => "select-auto-size") %>
   <%= aa.label :zip, "Zip Code:", :class => "control-label" %>
   <%= aa.text_field :zip %>                        
<% end %>                           

<%= f.fields_for :vital do |ab| %>
   <%= ab.label :birthday, "Birthday:", :class => "control-label" %>
   <%= ab.date_select :birthday, { :start_year => 1910, :end_year => 1995, :order => [:month, :day, :year] },{ :class => "select-auto-size" } %>
   <%= ab.label :sex, "Sex:", :class => "control-label" %>
   <%= ab.radio_button :sex, "Male", :id => "optionRadios1" %> Male&nbsp;&nbsp;
   <%= ab.radio_button :sex, "Female", :id => "optionRadios2" %> Female
   <%= ab.label :height, "Height:", :class => "control-label" %>
   <%= ab.select(:height_feet, options_for_select([["3'", 3], ["4'", 4]]), {}, :class => "select-auto-size") %>
   <%= ab.select(:height_inches, options_for_select([["3''", 3], ["4''", 4]]), {}, :class => "select-auto-size") %>
   <%= ab.label :weight, "Weight:", :class => "control-label" %>
   <%= ab.text_field :weight, :class => "input-mini" %><span>
   <% end %>                                

<%= f.fields_for :certificate do |ac| %>
   <label class="checkbox"><%= ac.check_box :C_ASEL %> Single</label>
   <label class="checkbox"><%= ac.check_box :C_AMEL %> Multi</label>
   <label class="checkbox"><%= ac.check_box :C_ASES %> Other</label>
<% end %>

<%= f.submit "Save & Continue", :class => "btn" %>

<% end %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:15:36+00:00Added an answer on June 17, 2026 at 4:15 am

    undefined method `update_attributes’ for nil:NilClass

    This is telling you that in your update controller action in ProfilesController you are calling update_attributes on a variable that is currently nil instead of an instance of the model you’re trying to update. Specifically

    def update
      if @profile.update_attributes(params[:profile])
        # ...
    

    You are not assigning @profile to any model instance, so it’s nil. You must do what you’ve done in your edit action.

    def update
      @profile = Profile.find(params[:id])
      if @profile.update_attributes(params[:profile])
        # ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When submitting the following form I am getting this error : Fatal error: Call
I am getting Error in submitting the form using AJAX and Jquery, following is
I am getting following error when press run in eclipse? Did any one know?
I am getting following error while executing my java code. What is this error
I'm getting the following error when I'm submitting a read action to Facebook -
Am getting following error message on calling WCF service: The formatter threw an exception
I am Getting following error on exporting the video using [exportSession exportAsynchronouslyWithCompletionHandler:^ Error: -[TiBlob
I am getting following error while installing the application on my device. before running
i am getting following error while getting data from dictionary -[__NSCFString objectForKey:]: unrecognized selector
I'm getting following error when I try to log onto phpMyAdmin. User * *

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.