I am trying to select an image randomly from a subdirectory inside my /app/assets/images directory using the Dir.glob() command, and then display it using image_tag . Somehow I can't get it to work.
Here is my code:
- @badges = Dir.glob("app/assets/images/badges/*") = image_tag @badges.sample
Which causes the following error:
ActionController::RoutingError (No route matches [GET] "/assets/app/assets/images/badges/produce.png"):
As you can see, the asset pipeline inserts "/ assets" in front of the directory. Okay, Rails, I'll meet you halfway. So, I will try to remove /app/assets from the request path to make it work and get the following result:
- @badges = Dir.glob("images/badges/*") = image_tag @badges.sample ActionController::RoutingError (No route matches [GET] "/assets"):
What am I doing wrong here? Thanks in advance for your help!
source share