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 6797977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:40:30+00:00 2026-05-26T18:40:30+00:00

Using Rails 3.1.0 def create @practice = Practice.new(params[:practice]) respond_to do |format| if (current_user.practices <<

  • 0

Using Rails 3.1.0

def create
@practice = Practice.new(params[:practice])

respond_to do |format|
  if (current_user.practices << @practice rescue false)

    pmf = current_user.practices_users.inspect # if this line is removed the following update_attributes method breaks!

    current_user.practices_users.last.update_attributes(:admin_flg => true, :first_name => params[:first_name], :last_name => params[:last_name])
    format.html { redirect_to home_dashboard_path, notice: 'Practice was successfully created.' }
    format.json { render json: @practice, status: :created, location: @practice }
  else
    format.html { render action: "new" }
    format.json { render json: @practice.errors, status: :unprocessable_entity }
  end
end
end

When the ‘pmf = …’ line is not present, I get this line

NoMethodError:
   undefined method `update_attributes' for nil:NilClass

When the ‘pmf = …’ line is present, the create action works normally. What is going on?

  • 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-05-26T18:40:30+00:00Added an answer on May 26, 2026 at 6:40 pm

    I don’t know the exact answer but I can help you debug…

    When you do

    pmf = current_user.practices_users.inspect
    

    then Rails is loading the whole set of practices_users (for current_user) from the database and when you call last a little bit later, it is calling the method last on an object of type Array.

    When you do

    current_user.practices_users.last
    

    without having made your pmf call, the whole set of practices_users has not been loaded from the database into an array, and Rails is not going to load the whole set because all you want is the last one. It would be a waste to load an array of items when all it needs to load is the last one. So it will generate SQL that only loads a single row from the database.

    In this sort of situation, you need to look at your console or development log to see exactly what SQL Rails is generating and why that SQL isn’t returning any value. Then it will become clear what’s going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : def create login(params[:email], params[:password]) if current_user flash[:notice] = Welcome
The rails 3 appis is using the create! method inside the create of a
I'm trying to spec the controller code: # ClustersController def create # create new
I have a create action like so in a rails controller: def create @user
I'm using the Rails 3 Vestal Versions gem: https://github.com/lailsonbm/vestal_versions I'd like to create some
I'm using Rails 3 and ruby 1.9 I'm trying to create a customized URL
Using Rails 3.0.9, I'm trying to redirect after a post to the create method
I've been trying to make my Rails create URLs to show records by using
OK, so I'm really new to Ruby on Rails. I'm using InstantRails, if that
Using Rails v2.1, lets say you have an action for a controller that is

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.