Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 before_action, pass parameters to invoked method

Tags:

ruby

I have the following code:

class SupportsController < ApplicationController   before_action :set_support, only: [:show, :edit, :update, :destroy]   .... 

Is it possible to pass a string to the method set_support to be applied for all 4 view methods? Is it possible to pass a different string to the method set_support for each method in the view?

like image 497
Parsa Avatar asked Oct 08 '13 23:10

Parsa


2 Answers

before_action only: [:show, :edit, :update, :destroy] do   set_support("value") end 
like image 79
Linus Oleander Avatar answered Oct 06 '22 20:10

Linus Oleander


You can use a lambda:

class SupportsController < ApplicationController   before_action -> { set_support("value") },      only: [:show, :edit, :update, :destroy]   ... 
like image 28
Kyle Decot Avatar answered Oct 06 '22 19:10

Kyle Decot