before_filter :authenticate_user!, except: [:index] / Rails 4
Call authenticate_user
before set_listing
, so that current_user
is not nil
before_action :authenticate_user!, :except => [:index]
before_action :set_listing, only: [:show, :edit, :update, :destroy]
Try this, this will allow guests to see listing supplied in the parameter:
def set_listing
unless current_user
@listing = Listing.find(params[:id])
else
@listing = current_user.listings.find(params[:id])
end
end
Update:
It appears that you want to display listings by parameter and not by the current_user
. If so then please update your set_listing
definition as follows:
def set_listing
@listing = Listing.find(params[:id]) if params[:id]
end