ruby on rails - What's the best way to store images for a carousel? -
i'm using ruby on rails. i'll have 2 carousels on landing page, , want know best way store , display these images:
option one
put images in assets/images , show them in carousel. if way, can loop through images in folder or i'll have specify each 1 of files?
option two
create model image column , loop through images have specific attribute?
other three
something else
thanks!
i'd recommend not place them directly in assets/images directory because add application-specific images app @ point won't want in carousel. folder app/assets/images/carousel, example, allows more determine images belong in carousel.
in controller, add following:
@images = dir.glob("app/assets/images/carousel/*.{gif,jpg,png}") then, in view, add following (assuming erb)
<% @images.each |image| %> <%= image_tag "carousel/#{image.split('/').last}" %> <% end %>
Comments
Post a Comment