Forked from jdickey/Trivial example of isolating Rails helper logic.rb
Last active
August 29, 2015 14:19
-
-
Save msuzoagu/e6f1a2e5ff80dc518ab8 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
# In app/helpers/users_helper.rb | |
require_relative 'users_helper/greet' | |
module UsersHelper | |
module Internals | |
end | |
private_constant :Internals | |
include Internals | |
def greet(user) | |
UserLinkGreeting.new(self).greet(user) | |
end | |
# ... | |
end | |
# In app/helpers/users_helper/ greet.rb | |
module UsersHelper | |
module Internals | |
class UserLinkGreeting | |
def initialize(helper_module) | |
@h = helper_module | |
end | |
def greet(user) | |
link_to "Hello, #{user.name}!", h.user_path(user) | |
end | |
private | |
attr_reader :h | |
end # end class UserLinkGreeting | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment