You can make your RoomsController also a CSS response to make this work:
Then you need to implement a visualization template for the CSS format:
.room { background-color: <%= @room.color1 %>; color: <%= @room.color2 %>; }
Please note that this is very similar to a regular template. You have to make sure that this will result in valid CSS.
You need to make sure the stylesheet is enabled when the user visits the page. Say a user can view their room design when they visit /rooms/1 . This will create an HTML template that we could define as follows:
<% content_for :stylesheet_includes do %> <%= stylesheet_link_tag(room_path(@room, format: :css)) %> <% end %> <div class="room"> Room Contents Here </div>
Note that I used content_for around the style sheet link tag. We can use this to make sure the style sheet link tag displays well in the layout head:
<head> <%= yield :stylesheet_includes %> </head>
Of course, you will need to fill in the details yourself, but this will be the most logical approach to the problem.
source share