Created
May 28, 2013 15:19
-
-
Save kulte/5663534 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
class MyApp::Interface::NavigationBar | |
include ActionView::Helpers::UrlHelper | |
delegate :url_helpers, to: 'Rails.application.routes' | |
def initialize(template, current_user) | |
@template = template | |
@current_user = current_user | |
end | |
def logo | |
# HTML to render a logo goes here. | |
end | |
def categories | |
# In this example, for arguments sake, let us assume that | |
# there exists some complex business logic to render | |
# categories based on who the requesting user is. In this | |
# case, this is an excellent place to abstract that logic | |
# to, allowing our views to worry only about rendering an | |
# instance of MyApp::Interface::NavigationBar. | |
end | |
def account | |
if @current_user.nil? | |
link_to :signup, url_helpers.signup_path | |
else | |
"Welcome #{@current_user.first_name}!" | |
end | |
end | |
def to_s | |
@template.render(partial: "navigation_bar", object: self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment