Reputation: 6817
by default, when i ask rails controller to do messages/index, he does
def index
respond_to{|fmt| fmt.html}
end
and shows app/views/messages/index.html.erb
there is a customer which wants his instance of the platform to display views differently (and changes cannot be done with css only).
solution i think of would be
create directory app/views/#{customername}, which would have same structure as app/views, but would only have views which have to override default ones.
setting an array constant containing list of views which have to be overriden (if not, they should load the default views)
CUSTOM_VIEWS["messages"]=["index","show","edit"]
somewhere in the customer-specific config file
in all controller actions do something like
def index
respond_to do |fmt|
fmt.html do
if CUSTOM_VIEWS[params[:controller]].include?(params[:action])
#override default app/views/messages/index.html.erb with app/views/customername/messages/index.html.erb
render "#{customername}/#{params[:controller]}/#{params[:action]}"
end
end
end
end
or is there better/faster solution/plugin to do that?
Upvotes: 1
Views: 3097
Reputation: 6817
i believe "view_paths" along with "prepend_view_path" can be an answer to my question
for example
http://www.axehomeyg.com/2009/06/10/view-path-manipulation-for-rails-with-aop/
upd:
solved with simple add to application_controller
def override_views
if APP_CONFIG['pr_name']!=nil
ActionController::Base.view_paths=[RAILS_ROOT+"/app/custom_views/"+APP_CONFIG['pr_name'],RAILS_ROOT+"/app/views/"]
end
end
where APP_CONFIG['pr_name'] is specific product name.
basically what it does is loading custom view from app/custom_views/customername/ if it exists for specific controller action, if not it loads default view from app/views/
Upvotes: 1
Reputation: 3360
This should help: http://railscasts.com/episodes/125-dynamic-layouts
Upvotes: 1