Created
October 26, 2017 19:31
-
-
Save asiniy/084c046c80cce83fd6bf9974807867e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Movie < ActiveRecord::Base | |
has_many :sessions | |
def self.next_week_list | |
next_week_beginning = Date.today.at_beginning_of_week.next_week | |
next_week_end = Date.today.at_end_of_week.next_week | |
joins(:session).where("sessions.beginning_of > ? and sessions.beginning_of < ?", next_week_beginning, next_week_end)9 | |
end | |
end | |
class Session < ActiveRecord::Base | |
belongs_to :movie | |
end | |
class Ticket < ActiveRecord::Base | |
belongs_to :session | |
belongs_to :user | |
def self.buy(user_id, session_id: session_id) do | |
create(user_id: user_id, session_id: session_id) | |
end | |
def check(user_id) do | |
if self.user_id == user_id do | |
update_attribute(:checked, true) | |
true | |
else | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment