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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:07:48+00:00 2026-06-03T03:07:48+00:00

I was previously adding my current user id to my tracks via the track

  • 0

I was previously adding my current user id to my tracks via the track controller’s create method using:

@track.user_id = current_user.id

This worked fine, however, i’ve now nested tracks within my releases model and am trying to do the same via callbacks in my releases model using:

before_save :add_user_to_tracks
before_update :add_user_to_tracks

def add_user_to_tracks
  tracks.each { |t| t.user_id = self.current_user.id}
end

I get an undefined method `current_user’ error, however, I know this is very close to working as if I test it using “99” instead of self.current_user.id it adds 99 to the user_id for each track in the db.

Any ideas why I can’t access current_user.id

  • 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-03T03:07:48+00:00Added an answer on June 3, 2026 at 3:07 am

    I think you should send user_id from your form using hidden field.

    If you don’t have user_id in Release model. You can create it as virtual attribute.

    class Release < ActiveRecord::Base
      attr_accessor :user_id
    
      before_save :add_user_to_tracks 
      before_update :add_user_to_tracks
    
      def add_user_to_tracks
        tracks.each { |t| t.user_id = user_id}
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, adding a (previously undeclared) int and a string in pseudocode: x =
I see a couple of previously answered questions about adding an item to an
Previously, I was passing information to a Silverlight control inside of the Page_Load method.
Previously, I asked about a clever way to execute a method on a given
previously, there is such method for Rectangle in MFC, i dont know why there
Previously within my Fitnesse fixture I was specifying an expected WCF exception using: exception[FaultException]
I was looking at adding rows dynamically to my HTML table using jQuery with
This is my current query: SELECT DISTINCT t.* FROM filter AS f INNER JOIN
I have an MVC form for adding a simple entity. I am using TextBoxFor(model
i'm trying to access the previously clicked paragraph/element. The user will click a paragraph,

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.