Rails: How can I let my users choose a design?

I am working with rails and am trying to implement a feature in my blogging application. I would like to be able to choose a design for my blog. I would of course design and code them, but after they are encoded, I would like to be able to use one of my projects.

How should I / should I approach this?

+3


source to share


1 answer


Create a controller to select the list of forms (check vaild for choice of course). Save your selection in session and try this:

In the layout:

= stylesheet_link_tag @custom_css

      

In application.rb



class ApplicationController < ActionController::Base
    before_filter :check_css

    def check_css
        @custom_css = session[:css]
        @custom_css ||= 'default'
    end
end

      

I think this should work.

Another idea is to change to a different layout.

class ApplicationController < ActionController::Base
    layout :custom_layout

    def custom_layout
        session[:css].nil? ? session[:css] : 'default'
    end
end

      

+4


source







All Articles