In my application I want to check to see whether or not a concert model exists with the same artist and date fields as a review model. If It does I want to add the review to the concert, if not then I want to create a new concert and review, because concert has_many reviews and reviews belongs_to concert...
So I wrote an exists? function in my concert controller:
def exists(@artist, @date)?
@concert_exists = @concerts.find_by_artist_and_date(artist: @artist, date: @date)
if @concert_exists.nil?
return false
else
return true
end
end
and then in my review controller I'm trying to do this for its create function:
def create
if Concert.exists(review_params[:artist], review_params[:date])?
#add review to this concert
else
@concert = Concert.create(:artist => "artist", :venue => "venue", :date => "2014-2-2")
@review = @concert.reviews.create(review_params)
@concert.artist = @review.artist
@concert.venue = @review.venue
@concert.date = @review.date
@concert.save
end
end
I keep getting an error that says
"syntax error, unexpected keyword_else"
Is my implementation incorrect and is there an easier way to do what I'm attempting?