Skip to content

Instantly share code, notes, and snippets.

@tylerhunt
Last active December 18, 2015 12:39
Show Gist options
  • Select an option

  • Save tylerhunt/5783839 to your computer and use it in GitHub Desktop.

Select an option

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.
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
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