Reputation: 747
Is there a way for me to add a separate background image for a specific post on my rails app?
In my rails app I have different mixtapes, and I would like to add a custom background image for some of the mixtapes "show" view (not for every mixtape though).
I would upload the images myself.
Is there a gem or a tutorial that shows me how to accomplish this? Thanks in advance.
Upvotes: 1
Views: 221
Reputation: 15525
There are different ways how to do it, and the easiest one (in my opinion) is to define a CSS selector that is responsible for that and to set it from your Rails application.
Something like the following pseudo-code:
%div{:class => @post.bg_class}
Then your application.css
file should include something like:
div.img1 {
background-image:url(img1.gif);
}
div.img2 {
...
}
Or you could style your div directly with the necessary style (not tested this one):
%div{:style => "background-image: #{@post.bg_image};"}
But the difficult part is to find for each different post a background image ...
Upvotes: 1