I have a review section which allows a user to write a review of another user following their meetup. I want to permit users to write a review following the start_time of their meetup.
The problem I am having is, immediately upon a meetup between two users being created the users are allowed to write a review for one another before their meetup start_time. The method I created finished_meetup?
is reading true all the time. I think this is due to my start_time being displayed wrong.
In the console, if I book a meetup for 8:30pm I get the following as the start_time start_time: "2000-01-01 20:30:00"
. Date is attached to time and cannot be eliminated because "Represent a time with no date in ruby".
How would I set up the method finished_meetup?
to allow for the reviews to be done following the meetup and not beforehand.
shema.rb:
create_table "user_meetups", force: true do |t|
t.integer "user_id"
t.integer "friend_id"
t.string "state"
t.datetime "created_at"
t.datetime "updated_at"
t.date "start_date"
t.time "start_time"
user.rb
def find_corresponding_friend_id(friend_id)
self.user_meetups.where(friend_id:friend_id).present?
end
def already_reviewed
self.reviews.map{|d| d.review_writer_id}
end
def finished_meetup?
user_meetups.where("start_time < ?", Time.new("2000/#{Time.now.strftime("%m/%d")}"))
end
users/show.html.erb
<% if @user.find_corresponding_friend_id(current_user.id) && @user.already_reviewed.empty? && @user.finished_meetup? %>
user_meetup.rb
class UserMeetup < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'
validates :start_date, :start_time, presence: true
# attr_accessor :user, :friend, :user_id, :friend_id, :state
after_destroy :delete_mutual_meetup!
state_machine :state, initial: :pending do
after_transition on: :accept, do: [:accept_mutual_meetup!]
after_transition on: :block, do: [:block_mutual_meetup!]
after_transition on: :unblock, do: [:accept_mutual_meetup!]
state :requested
state :blocked
event :accept do
transition any => :accepted
end
event :block do
transition any => :blocked
end
event :unblock do
transition any => :accepted
end
end
def self.request(start_date, start_time, location, description, learners, user1, user2)
transaction do
# Rails.logger.info "user1 is #{user1.inspect}"
# Rails.logger.info "user2 is #{user2.inspect}"
meetup1 = UserMeetup.create!(start_date: start_date, start_time: start_time, user: user1, friend: user2, state: 'pending')
# Rails.logger.info "meetup1 is #{meetup1.inspect}"
meetup2 = UserMeetup.create!(start_date: start_date, start_time: start_time, user: user2, friend: user1, state: 'requested' )
# meetup1.send_request_email
# meetup1
end
end