问题描述:

I notice that everything regarding Rails and Sprockets falls into the 'domain/assets/' URL, but I have this issue with certain files that are trying to get CSS and image files from:

somedomain/assets/css/{filename}

somedomain/assets/images/{img_name}

I'm trying to find some way to split up the paths of those assets so they don't all go into the same /assets path so that the URLs work. I thought maybe I could either do that in the configuration, but I didn't find anything other than renaming config.assets.prefix, or the routes.rb, because I thought something like "get /assets/css" would work but I don't know where to point it to.

In any case, at this point I'm stuck (btw, this has been in development. in production, I'm running into somewhat of a different issue where the javascript_include_tag is trying to go to /javascripts path).

网友答案:

I did this in my application.rb in config:

config.assets.enabled = true
config.assets.paths << "#{Rails.root}/app/assets/css"
网友答案:

Got the answer. Sorry if my question and examples weren't clear enough... I'm always terrible at it...

Anyways I took a look at the sprockets documentation (not the sprockets-rails docs) and this is what I did (modified config.ru):

map '/assets/images' do
  environment = Sprockets::Environment.new
  environment.append_path 'app/assets/images'
  run environment
end

map '/' do
  run Rails.application
end

Unfortunately, I don't fully understand what's going on in the config.ru other than the fact that the entire application starts here but it looks like that mapping lets me serve it up in this way (Surely, on something like AWS I can use nginx but for Heroku and overall, this seems to make things easier).

相关阅读:
Top