Created
November 19, 2010 01:56
-
-
Save baldwindavid/706019 to your computer and use it in GitHub Desktop.
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 | |
before_filter :set_counter | |
helper_method :counter | |
protected | |
def counter | |
@counter | |
end | |
def set_counter | |
@counter = Counter.new | |
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 Counter | |
def initialize(i = 1) | |
@i = i | |
end | |
def current | |
@i | |
end | |
def increment!(by = 1) | |
@i += by | |
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
%h3= "#{counter.current}. Something" | |
%p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | |
%h3= "#{counter.increment!}. Something Else" | |
%p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | |
%h3= "#{counter.increment!}. Other Stuff" | |
%p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is handy in cases when you need to manually set numbering in a view. The example (index.html.haml) is not a good one given you would obviously use an ordered list with that content...but you get the point.