I am probably missing something extreamly obvious, but I can’t figure this our for the life of me…
I am trying to preform a simple before_filter check in my Orders_Controller, to see if the Devise current_user.vendor_id == params[:vendor_id]. It returns false every time, redirecting my to the root_path, as I have it set up in my orders_controller…
before_filter :check_vendor
.
.
.
private
def check_vendor
unless current_user.vendor_id == params[:vendor_id]
redirect_to root_path, :flash => { error: "Sorry, but you don't have sufficient privlidges to view that page" }
end
end
The strangest thing is when I login with a user, and navigate to
http://localhost:3000/vendors/3/orders/
and have this code in my index:
<%= current_user.vendor_id %> <%= params[:vendor_id] %>
It prints out on in the orders#index view:
3 3
Which should mean that when I use the same logic in the controller, it see’s that both values are ‘3’ (or whatever the current_user.vendor_id and params[:vendor_id] is)
Any help would be greatly appreciated 🙂 Sorry if it is an obvious answer, I am pretty new at Rails still.
Are you sure you’re sending de param[:vendor_id] in the first request to the controller?
I would add
gem 'debugger'to my gemfile, runbundle install, and putdebuggerjust above the comparisson in the before_filter.Then check params and current user values.