Skip to content

Instantly share code, notes, and snippets.

@kulte
Created May 28, 2013 15:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kulte/5663544 to your computer and use it in GitHub Desktop.
Save kulte/5663544 to your computer and use it in GitHub Desktop.
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 render
@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