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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:59:43+00:00 2026-06-06T13:59:43+00:00

I created an instance variable ( @edit_id ) in the user_controller the update action.

  • 0

I created an instance variable (@edit_id) in the user_controller the update action.

def update
  ......
  @edit_id = 1
  ......
end

and I have an Active Record Callbacks in the user_model

has_many :details
after_update :create_user_details
  ......
  private
  def create_user_details
     detail = user.details.build
     detail.edit_id = @edit_id
     #(this @edit_id is the user_controller update action 
     #created instance variable, but **@edit_id is nil**)
     detail.save
  end

I how use the instance variable in the callback action

  • 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-06T13:59:45+00:00Added an answer on June 6, 2026 at 1:59 pm

    You cannot use instance variables from your controller in your model.
    They both are different instances of different objects and therefore don’t share instance variables.

    You need to provide your model with this value by setting it in it’s instance like this :

    model Foo
      attr_accessor :edit_id
    
      private
      def create_user_details
       detail = user.details.build
       detail.edit_id = edit_id
       detail.save
      end
    end
    

    Then, in your controller, you specify the value to the model and save it.

    def update
      @foo = Foo.new
      @foo.edit_id = 1
      # Whatever other business logic you want to do
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a student class and every student instance created needs to be stored
I have a org.eclipse.swt.browser.Browser instance created in a composite. I would like to know
I have the following create action: def create @report = Report.new(params[:report]) @file = params[:report][:data_file]
I would like to be able to create a variable that holds an instance
I created many instances of a PlotHandler class. An instance must keep it's variables
I'm defining my own AR class in Rails that will include dynamically created instance
I created an instance of UIAlertView with two buttons and in the interface file
If I created an Instance of a class how long does the Object live
I am trying to access the singleton instance created by my WCF service but
I have created a system that automatically registers function objects (functors) into a map

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.