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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:39:30+00:00 2026-06-17T15:39:30+00:00

First and foremost, thanks to everyone taking time to read through this post. Many,

  • 0

First and foremost, thanks to everyone taking time to read through this post. Many, many thanks in advance.

I’m currently building a small registration system for classes. I’m stopping users from registering twice to the same event through the model with “validates :user_id, :uniqueness => {:scope => :occurrence_id}” in my Registration controller. I want to extend this to my views by greying out a “register” button.

I’m thinking that the best way is by writing a method in the occurrence model that goes something like this:

def already_registered?(user)
  if user.id == self.registrations.find()
    false
  else
    true
  end
end

Now I know for sure that this doesn’t work. How can I search if one occurrence has been has not been register by the current user?

models/registration.rb

class Registration < ActiveRecord::Base

  belongs_to :user
  belongs_to :occurrence

 attr_accessible :occurrence_id, :registration_date, :user_id, :occurrence, :user

 validates :user_id, :uniqueness => {:scope => :occurrence_id}

end

models/occurrence.rb

class Occurrence < ActiveRecord::Base

  belongs_to :course
  belongs_to :location
  has_many :registrations
  has_many :users, :through => :registrations

  validates :price, :presence => true

  attr_accessible :course_id, :datetime_end, :datetime_start, :location_id, :price, :teacher_id, :class_size

  def remaining_seats
    self.class_size - self.registrations.count
  end
end
  • 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-17T15:39:31+00:00Added an answer on June 17, 2026 at 3:39 pm

    I’m not sure if I really understand your question, but try with

    def already_registered?(ocurrence)
      self.registrations.where(:ocurrence => ocurrence).any?
    end
    

    and you call it with

    current_user.already_registered?(current_ocurrence)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First and foremost, are there many android developers here? Is this a good place
First and foremost, thank you all for reading this and helping, I'm very grateful.
I am first and foremost a perl coder, but like many, also code in
This is more like general knowledge to understanding Android Market. So, first and foremost,
First time posting on stack overflow. I've spent hours scouring over many Google searches
First and foremost, I have searched this thoroughly and I'm not convinced with any
First and foremost, this is not a question about generating a serial number for
First and foremost, I apologize for any vagueness in this question. At this point,
First and foremost: JSON and XML are not an option in this specific case,
First and foremost, this is for an assignment, so most of the really cool

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.