Friday, 5 September 2014

HOW TO APPLY DIFFERENT LAYOUTS FOR SAME CONTROLLER

class Events::EventsController < AuthenticatedController
layout :user_layout
#for admin
def new
end
def show

end
#for classifieds layout
def classifieds

end
protected
def user_layout
if params[:layout]=="admin"
"admin"
else
"classifieds"
end
end

end

Here i am applaying admin layout to new and show, classfieds to classifieds..

Inorder to apply those two layouts we need to pass layout="admin" as a paramater, in the same way layout="classifieds" for classifieds layout..

Ex: <li><a href="/events/new?layout=admin"><i class="fa fa-angle-double-right"></i>Events</a></li>
end

No comments:

Post a Comment