Rails 3.1 sub uri assets path issue - ruby-on-rails

I am currently using rails 3.1.0.rc1 and when i deploy it to a server which is using passenger and it is deployed to a suburi.
But when I go into look at the site, path to the style-sheets and java-script files are not being included because of the path.
Can someone let me know how to specify the path in the environments so that all the assets (images , style-sheets and java-script ) point to the right path ?

This issue was fixed on Rails 3.1.0.rc4. You no need to specify anything for the config.assets.prefix unless you want the change the default /assets.

I got around it using YourApp::Application.config.assets.prefix = "/suburi/assets". Acording to issue #1489, helpers didn't respect this till last Tuesday, so you'll have to use 3.1rc4. Url's seem to get created correctly, so it may be more of a phusion problem.

Related

Getting 404 for Rails Static Assets

I'm using Carrierwave to handle file uploads. Files get stored under public/uploads/. Project uses Ember.js templates, and the img tags point to the proper src. (I've verified that the files are present at those paths.) However, the server returns a 404 for each.
It looks like this is a common problem, and the common solution is to:
config.serve_static_assets = true
However, this isn't working. I'm still getting 404s. Any other ideas about how to deal with this?
It should be noted that I'm not using Apache or nginx.
Rails no longer compiles the assets without digests. In order for this to work properly, you need to use a rails helper to include the proper asset name (with the digest), or use a gem like https://github.com/alexspeller/non-stupid-digest-assets as a workaround.

How do I customize the URL path to 'subpaths' for the assets pipeline?

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).

Rails 3.2 Deploy to Subdirectory Kind of Working

I am trying to deploy my Rails 3.2 app to a subdirectory, /support, on an Apache server. Consulting the various posts, the only solutions that seem to have helped involve setting up a symbolic link on the server and changing css image references slightly (two dots '..' required before /assets in the css url references--I can't seem to find the post on that one now). I am getting success in deployment to production with Capistrano, but then strangely after awhile something changes, the /support reference breaks and the stylesheets don't load. Any suggestions?
oh no, please don't deploy rails as sub-uri in that way, you are making yourself in trouble.
So far as I see, ( according to this post: http://kb.site5.com/ruby-on-rails/how-to-deploy-a-rails-3-application-to-a-sub-directory/ ) you created soft links, modified your routes.rb, and changed RAILS.root in environment.rb, and also changed your assets files... all of these make your rails app messed up.
I suggest you use 'passenger' as rails server and checkout this post: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rack_to_sub_uri, it's quite easier and simplier

Carrierwave to different upload folder | Routes not correct

I need to configure my carrierwave gem in rails to use a different upload folder beyond the whole rails scope.
I have a VPS and using RVM, ruby, rails. I'm deploying with capistrano, but every time a deploy takes place, the upload folder changes to the new deployed version and not taking all the older images with it.
I want to have a folder that is static and not going to be changed every deployment. But i cant seem to get the solid settings, the cache and store directories are being changed. Also when i'm using Rails.root (this gets me the current capistrano deployment folder) need to get 1 or 2 maps above this folder (way beyond the rails.root)
How could i change this settings so that this is going to work?
Thank you for your time
Update
Changed to full url : /home/deploy/rails_apps/site/uploads/ and its being uploaded. Only when i want to display the picture, this gives me a X mark. If i want to open the image by the firebug inspector, it gives me the error:
No route matches [GET] "/home/deploy/rails_apps/site/uploads/product/image/5/thumb_test.png"
How must i make a route that's beyond this application?
Are you using shared configs with symlinks with Capistrano on your VPS?
If so, you can make there a config for carrier wave picture folder which won't get overwritten. Than you can also use different setting on dev- and deployment machine.
You can take a look at this screencast: Capistrano Tasks from Ryan Bates
Hope it helps.

Wrong image path when running in a subdirectory of my Rails app

I have a rails app running in a subdirectory, like www.domain.com/sub.
The problem is that if I set a image path in my css, like
/images/my_image.png
it breaks when I upload it to my server. I need to set
/sub/images/my_image.png
then it breaks in my development environment.
The same problem occurs in my .js files.
I read something about the rails_relative_url_root environment variable, but couldn't get it to work.
Could anyone help me?
You could use URLs relative to the stylesheet. In your CSS, instead of this:
/images/my_image.png
Do:
../images/my_image.png
If you're on OSX you can set up passenger to mirror your production environment (put app in /sub folder) ... or you can look into less/sass ... I'haven't used them much but I believe they might allow you set paths for assets programmatically

Resources