Skip to content

Instantly share code, notes, and snippets.

@avit
Last active December 15, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avit/5322622 to your computer and use it in GitHub Desktop.
Save avit/5322622 to your computer and use it in GitHub Desktop.
IDEA: To add layout options for Rails

Override ActionController layout class method to take a view_options hash, whether or not the actual layout template is being changed:

layout "foo", view_options: {sidebar: 'special'}
layout view_options: {sidebar: 'special'}

Define a LayoutOptions module in the controller class and give it to the view helpers. It would define methods:

module LayoutOptions
  def sidebar
    'special'
  end

  def sidebar?
    true
  end
end

These options should be inheritable and overrideable by subclasses. Should keys be cleared when changing the layout?

Not sure if these methods should just be exposed directly to the view as sidebar or somehow scoped to layout.sidebar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment