M
M
Maxim Filippov2014-09-08 19:03:09
Ruby on Rails
Maxim Filippov, 2014-09-08 19:03:09

Where to store the background image of a Rails application?

I have several sections in my application, each of which uses its own background, there is also a “default” background that is displayed on all other sections and on the sections described above if the background is not loaded there.
Question: how best to organize the storage and loading of background images?
I use the carrierwave gem, it was possible to create a field in the section model in which to store the background using carrierwave, which would be enough, but then what to do with the default background?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Platonov, 2014-09-08
@kirillplatonov

app/assets/images

F
FanKiLL, 2014-09-08
@FanKiLL

That is, sections are dynamic, for example, categories from the database?
Whereas in another way, if you still want to change the picture sometimes, then store the path to the picture in the database.
And if everything is fixed, for example, make a separate layout for a specific controller, where to register a different background image and use this layout in the controller

class CategoriesController < ApplicationController
  layout 'имя лайаута из папки layout'
end

Moreover, you are already loading the model anyway, which means there will be no extra request.
If the background pictures will not be changed, then you can put them in app/assets/images beforehand
so that the pictures have model or category names.
And if they change often or categories are created dynamically from the admin panel, for example, I don’t see any other way how to store the path in the database and fill it in and set it in the model.
mount_uploader :background, BackgroundUploader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question