Add a before_render filter to rails. Compatible with Rails 4 only
Switch branches/tags
Nothing to show
Clone or download
#6 Compare This branch is 18 commits ahead of shell:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
Gemfile
MIT-LICENSE
README.md
Rakefile
before_render.gemspec

README.md

Before Render

Introduction

Add a hook like before_filter to your controllers that gets executed between when your action is completed and the template is rendered. It can really DRY up loading some data that is used for views (headers / layouts / etc).

Plugin heavily based on Vladimir Penkin's rails3_before_render which in turn is based on before_filter for Rails 2 by Todd Willey.

Provided methods:

  • before_render
  • prepend_before_render
  • skip_before_render

Installation

gem 'before_render'

Warning: Rails 4 only.

Usage

before_render / prepend_before_render / skip_before_render works as other filters. Options like :except and :only can be passed to filter.

class PostsController < ApplicationController
  before_render :ping, :except => [:destroy]

  def index; end     

  def new; end

  def show; end

  def destroy; end                                                                          
          
  private
    def ping
      Rails.logger.info "Ping-Pong actions"
    end
end       

Method ping will be executed after your actions and before template is rendered.

TODO

  • Tests should not throw runtime error(happening right now if comment one of provided aliased methods)

Author

Copyright (c) 2013 Nilesh Chaudhari, released under the MIT license. Plugin heavily based on Vladimir Penkin's rails3_before_render which in turn is based on before_filter for Rails 2 by Todd Willey.