Skip to content

Instantly share code, notes, and snippets.

@superacidjax
Created December 18, 2013 16:41
Show Gist options
  • Save superacidjax/8025507 to your computer and use it in GitHub Desktop.
Save superacidjax/8025507 to your computer and use it in GitHub Desktop.
Old and New Layout Switching for Legacy
# put all new_layout views in the following new folder: app/views_new_layout
## Do NOT put the views in app/views
# you need a migration in Users called new_layout:boolean this does not need a default value
## The below code will assume the new layout for all users, unless they explicitly say no.
### for example, if you want to put an ajax box at the top of the new page that says
#### "This is our new layout. Switch back to old one? If they click the link, then it sets the boolean to false.
##### You can also have them switch back and forth easily. If they make no preference (thus the boolean is nil,) then new layout is used.
# You can reverse this logic very easily if you want to default to the old layout.
# in application_controller.rb
before_filter :check_for_new_layout
# rails 4
## before_action :check_for_new_layout
def check_for_new_layout
prepare_for_new_layout unless current_user && current_user.new_layout == false
end
def prepare_for_new_layout
prepend_view_path Rails.root + 'app' + 'views_new_layout'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment