You can make your RoomsController respond to the CSS format as well in order to get this to work:
# app/controllers/rooms_controller.rb
class RoomsController
def show
@room = Room.find(params[:id])
respond_to do |format|
format.html
format.css
end
end
end
Then you need to implement a template to be rendered for the CSS format:
/* app/views/rooms/show.css.erb */
.room {
background-color: <%= @room.color1 %>;
color: <%= @room.color2 %>;
}
Note how this is very similar to a regular template. You need to make sure that this results in valid CSS.
You need to make sure the stylesheet is included when the user visits the page. Let's say a user can browse their room design when they visit /rooms/1. This will render a HTML template, which we could define as follows:
<!-- app/views/rooms/show.html.erb -->
<% content_for :stylesheet_includes do %>
<%= stylesheet_link_tag(room_path(@room, format: :css)) %>
<% end %>
<div class="room">
Room Contents Here
</div>
Notice that I've used content_for around the stylesheet link tag. We can use this to make sure the stylesheet link tag is rendered nicely in the head of the layout:
<!-- app/views/layouts/application.html.erb -->
<head>
<%= yield :stylesheet_includes %>
</head>
Of course you'll need to fill in the details yourself, but this would be the most logical approach for the problem.