Last active
December 18, 2015 12:39
-
-
Save tylerhunt/5783839 to your computer and use it in GitHub Desktop.
Modify Rails view binding to allow values to be explicitly exposed to the views and telling the instance variables to GTFO.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::Base | |
| protect_from_forgery with: :exception | |
| def render(*args) | |
| options = args.extract_options! | |
| options[:locals] ||= @_exposed | |
| super *args, options | |
| end | |
| def view_assigns | |
| {} | |
| end | |
| private | |
| def expose(name, value) | |
| (@_exposed ||= {})[name] = value | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class UsersController < ApplicationController | |
| def show | |
| expose :user, User.find(params[:id]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment