In my application controller i use around_action to set the time zone in every controller action :
class ApplicationController < ActionController::Base
around_action :user_time_zone
def user_time_zone(&block)
Time.use_zone("Central America", &block)
end
end
but in a specific controller i won't to apply this time zone with some actions, so i want something like this :
around_action :user_time_zone, except: {controller: "foo" & action: "bar" & action: "other_action"}
there is a way to this ?
A 'before action review' (BAR) is a tool to help a team asses the current knowledge and experience they already have as a way to inform the planning stages of a new project.
When writing controllers in Ruby on rails, using before_action (used to be called before_filter in earlier versions) is your bread-and-butter for structuring your business logic in a useful way. It's what you want to use to "prepare" the data necessary before the action executes.
Rails after filters are executed after the code in action controller is executed. Just like before filters, after filters are also defined at the top of a controller class that calls them. To set it up, you need to call after_filter method.
The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. It is responsible for routing external requests to internal actions.
In specific controller where you do not need this filter just skip it using 'skip_around_filter'
class FooController < ApplicationController
skip_around_filter :user_time_zone, :only => [:bar]
end
Note: skip_around_filter is supported in Rails 3.2.1 or higher version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With