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

  • Home
  • SEARCH
  • 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 3999012
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:36:04+00:00 2026-05-20T07:36:04+00:00

I created a Ruby on Rails application (2.3.9) where users can record workouts. I

  • 0

I created a Ruby on Rails application (2.3.9) where users can record workouts. I am trying to implement a ‘star’ system which would allow a logged_in user to star workouts from other users that they want to remember.

I am doing this by creating a Star resource (associations below). I am successfully creating a deleting records in my Star table and now want to conditionally display view code based on if a current_user has already starred a workout.

I am displaying all workouts through a partial for _workouts.html.erb. For each workout, I would like to either display the <% remote_form_for [workout, Star.new]... or You have already starred this workout.

Workout :has_many => :stars

User :has_many => :stars

Star :belongs_to => :workouts
Star :belongs_to => :users

I imagine I will have to create a named_scope in Star.rb that looks to see if if there is an existing star record where the workout_id matches workout.id and where current_user.id matches the star.user_id match for that workout. It confuses me just typing this. Please help.

  • 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-20T07:36:05+00:00Added an answer on May 20, 2026 at 7:36 am

    You can create a has_many ..., :through => ... relationship, and then use #include? to check for an association.

    # User
    has_many :starred_workouts, :class_name => 'Workout', :through => :stars
    
    # View
    <% if current_user.starred_workouts.include? workout %>
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a blog application using Ruby on Rails which includes the ability
At the moment I have a Ruby on Rails application which maintains my Users,
I have built a blog application w/ ruby on rails and I am trying
I created a Ruby-on-Rails project using NetBean 6.8, which operates as expected on port
I'm trying to create a ruby on rails ecommerce application, where potential customers will
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
I have a Ruby on Rails application with a PostgreSQL database; several tables have
I'm building an iPhone application that talks to a Ruby on Rails backend. The
Greetings, all, I'm working on an application in Ruby on Rails where we need
I'm trying to make a local backup of the data from my Rails application,

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.