Skip to content

Instantly share code, notes, and snippets.

@iain
Created December 30, 2011 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save iain/1541602 to your computer and use it in GitHub Desktop.
Save iain/1541602 to your computer and use it in GitHub Desktop.
module Expose
def expose(*methods)
attr_reader *methods # for when you still only assign ivars in the action
helper_method *methods
end
end
ActionController::Base.extend Expose
<% widgets.each do |widget| %>
<p><%= widget.name %></p>
<% end %>
class WidgetsController < ApplicationController
expose :widgets, :widget
def index
end
private
def widgets
@widgets ||= Widget.all
end
def widget
@widget ||= Widget.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment