I am trying to ‘connect’ two tables AdHour and Ad in the method below.
However, the line with the asterisks is causing the following error:
“You have a nil object when you didn’t expect it!
The error occured while evaluating nil.user_id”
I’ve included the model for both AdHour and Ad.
Why doesn’t the script like how I am connecting the tables??
userid = @session[:user].id
@ad_hour = AdHour.find(@params[:id])
***** if (@ad_hour.Ad.user_id != userid)*****
render_text “You do not have permission to modify this ad.” and
class AdHour < ActiveRecord::Base
class Ad < ActiveRecord::Base