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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:39:06+00:00 2026-06-04T18:39:06+00:00

i was wondering if it was possible to get the current object in a

  • 0

i was wondering if it was possible to get the current object in a model? ie i have a

FavoriteRelationship model which

belongs_to :user
belongs_to :lesson

my lesson model is

has_many :favorite_relationships
has_many :users, :through => :favorite_relationships

i have an association with my user model as well (not important)

ive been trying to do the method inside my FavoriteRelationship

def lesson_owner
    self.lesson.user
end

to retrieve the user that belongs to that lesson in the FavoriteRelationship but it doesn’t seem to work. it returns nothing, even when i do

self.lesson.inspect

retrieving even the lesson which is in the FavoriteRelationship model isn’t working. could someone shed some light on how to do this?

i essentially want the lesson that’s associated with the FavoriteRelationship model. in my FavoriteRelationship table, i have the attributes,

:id, :user_id, :lesson_id.

and the :lesson_id should be the value im trying to acquire so i can get the user afterwards

thank you for your help and time

@update.

so im basically using trying to grant a ‘badge’ when a user favorites someone elses lessons. i have..

def create
    @lesson = Lesson.find(params[:favorite_relationship][:lesson_id])
    puts 'before favorite'
    current_user.favorite!(@lesson) 
    puts 'after favorite'
    @favorite_relationship = @lesson.user    
    respond_to do |format|
      format.html { redirect_to @lesson }
      format.js
    end
end

my badge granting comes from…

    grant_on 'favorite_relationships#create', :badge => 'got-favorited',
         :to => :lesson_owner

which takes in a method that returns who im granting to, that’s why i created that method.

when i do

puts self.lesson.inspect

nothing comes up, not nil or anything. i know that my favoriting works, it creates the relationship in the db. the only thing i could possibly think is happening is that…it tries to grant the badge before the relationship gets created. hmm…i put print statements and it does seem like it goes into lesson_owner after the create_favorite_relationship gets called and returns. maybe it hasn’t created it yet in the db? like a millisecond too fast? the favoriting happens asynchronously.

do i need to have some more associations set up?

  • 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-04T18:39:08+00:00Added an answer on June 4, 2026 at 6:39 pm

    So, what does this self.lesson.inspect return? nil or NoMethodError?
    Show us your migrations and check what’s actually in the database.
    This might be your relation is just missing the link to the lesson (lesson_id is NULL)…

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

Sidebar

Related Questions

I was wondering if it's possible to get the Window object for the current
I was wondering if it were possible to get the current time of a
I was wondering how to get the current users online and their IP address.
Possible Duplicate: Get current date and time in PHP I was wondering how can
I was wondering if it is possible to edit the current object that's being
I am wondering if its possible to get $(this).scrollTop() value after an anchor jump.
I am wondering if it´s possible to get the IP address of the airplay
I was wondering if it is possible to get the places of interest in
I'm wondering if it's possible to get the address of an individual element of
I was wondering if it's possible to get the frequencies present in a file

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.