Created
December 30, 2011 21:42
-
-
Save iain/1541602 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
<% widgets.each do |widget| %> | |
<p><%= widget.name %></p> | |
<% end %> |
This file contains 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 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