Ask A Question


You’re not receiving notifications from this thread.

Rails 6: Separate styles and layout for dashboard and main (front) site

Joan Gabun asked in Rails

I will try to explain my issue as much as I can.

I hope you guys can understand and give me an idea / help me.

So I am working on a practice app. There are two separate bootstrap html/css design for both of my dashboard and main site.

Here's the dashboard design:

Here's the main site design:

Both of these used bootstrap but separate set of custom design css as well js files.

So far I created a CRUD feature for both of my pages and posts (controller, migration, model, views)

Now I am confused on whether I'll create another controller for the dashboard and create a different folder on the views for that and how I can actually link the dashboard to my created pages, controller views so far as well as controller. Wondering also if I can create separate layout file for my dashboard and main site.

I hope it make sense.


You should create two layouts :

One 'main.html.erb' et one 'dashboard.html.erb'

And then specify on your controllers which layout they should use.

main_controller.rb should have layout 'main'
dashboard_controller.rb should have layout 'dashboard'

Those two controllers should inherit from ApplicationController. And then each controller in your app should inherit from either MainController or DashboardController.

Then you should have two css and js application files.

It depends if you use sprockets or webpacker but either way each layout should have its own application pack (webpacker) or manifest file (sprockets).

Like main.scss and main.js file on one side, and dashboard.scss and dashboard.js on the other.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.