Home send parameter through before_action
Reply: 1

send parameter through before_action

luis31
1#
luis31 Published in 2017-12-07 17:20:31Z

I am using a before action to execute an action called "can_accede" (this is in my aplication_controller) before accessing my index view, this action will look for a record to verify if the user can access my index view, but I need to send a parameter to that action to know what record to look for.

this is my "can_accede" action

def can_accede
  @can_accede = current_usuario.try(:perfiles).find_by_Descripcion(params[:Module_name]).try(:Listar)
  if @can_accede != true
    redirect_to root_path, alert: "you don't have permission."
  end
end

this is my before_action:

before_action :can_accede, only: [:index]

it is possible to send to the action can_accede through the before_action a parameter param [: Module_name]?

Daniel Westendorf
2#
Daniel Westendorf Reply to 2017-12-07 17:28:27Z

The params object will be available in the method, so you can simply call params[:whatever] in can_accede.

FWIW, you should look into an authorization gem to unify your methods of authorization. Pundit and CanCanCan are good options.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.356377 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO