Ruby on Rails Base URI - ruby-on-rails

I am using Phusion Passenger to host a rails app on an Apache server (I am very new to rails).
I have several domain names that point to the same server, and a mod_rewrite is used to direct different domains to different subdirectories.
I was having a difficult time getting the app to load at all, but I set RailsBaseURI to the path relative to the DocumentRoot, and everything worked fine. However, all the links generated throughout the application include this BaseURI in them.
How can I configure the app to generate URI's relative to the naked domain name instead?

Related

Rerouting to AWS hosted assets from a Heroku Rails app

I have a Heroku hosted Rails app that has reached the 300MB limit for the slug size and can no push to Heroku. To fix this issue, I've setup an AWS S3 account and want to redirect the assets being requested from my Rails app to the new S3 location. The Rails app is basically just serving JSON files that point to the static assets using a relative URL. An iOS app using the Rails JSON then has a hardcoded domain URL, and appends the path to the resources to that domain and requests assets it needs.
I want to update my Heroku app and change my asset locations without requiring an update to the iOS app in order to change the asset domain. So, I need to redirect static asset requests from the Rails app to the AWS server.
In my git repo, I've ignored the assets in the public folder that I've moved to the AWS server. The asset files are present on my local machine, but are not part of the git repo when uploaded to Heroku.
So far I've tried changing the config.action_controller.asset_host which does not seem to work since these are static assets and are being returned by the web server before Rails gets it.
I tried using routes rules to redirect to a different domain, but these routes never seem to be captured. The static files appear to be returned before the Rails app has a chance to handle the request.
I've tried using the rack-rewrite gem to try and redirect my assets to a different domain with the following in `initializers/rack_rewrite.rb:
require 'rack/rewrite'
AppNamespace::Application.config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
r301 %r{/images(.*)}, 'http://my-subdomain.amazonaws.com/images$1'
end
This doesn't seem to work either and it always just returns the static files.
So far I've been trying for hours to figure out the proper way to handle this situation. I'm not a Rails developer by trade, I build iOS apps, so please let me know if I'm going about this the wrong way or completely missed the "right" way of doing this.
I solved this using routes and the 'rails_serve_static_assets'. I had to move the local images out of the public folder in order to avoid Nginx from returning the images before hitting the Rails app. The route ended up like so:
match '/images/(*path)', :to => redirect { |params, request|
"#{Rails.configuration.assets.aws_url}#{request.path}"
}

What is difference between application.rb and environment.rb in Ruby on Rails?

I am new to Rails and I have good knowledge of ASP.net. In ASP.net web applications I have one web.config to do all my settings, but in Rails there are several config files and I would like to know now, what are the differences between them and what is the purpose of these files are.
Basically the different config files build together the web.config as you know it from ASP.net.
environment.rb
Rails has different run-levels, like ASP.net has it's environments too. In the environment.rb file you configure these run-levels. For example, you could use it to have some special settings for your development stage, which are usefull for debugging.
application.rb
The purpose of this file is to configure things for the whole application like encoding.
You can find some more information in the guide, like it was mentioned by davids.
From the guides:
config/environment.rb
This file is the common file required by config.ru (rails server) and Passenger. This is where these two ways
to run the server meet; everything before this point has been Rack and
Rails setup.
This file begins with requiring config/application.rb.
config/application.rb
This file requires config/boot.rb, but only if it hasn’t been required before, which would be the case in rails
server but wouldn’t be the case with Passenger.
Then the fun begins!

Where should I put files to be sent via send_file in Rails 3?

Where am I supposed to put files to be served via send_file in Rails 3?
Suppose I'm serving a browser extension that may be updated once a month or two, should I put it in the asset pipeline? And how can I access it from the controller?
If I refer to it using #{Rails.root} it won't work in the production environment.
I don't want to have to change config.action_dispatch.x_sendfile_header every time I'll deploy on a different webserver, and I don't want to set config.serve_static_assets = true since this is a distortion of the development environment.
You should put them in a directory outside of Public, otherwise they will be viewable by the browser directly without authentication.
I usually create a directory in Rails.root, something like
Rails.root
- app
- config
- db
- secure_files
So the files will be present in secure_files.

Deploying openx into ruby on rails application

I'm trying to integrate openx into an Ruby on Rails 2 application and I'm deploying my rails application on the root of my server like 'http://mydomain.com/' so i put the openx folder in the public so it'd load in 'http://mydomain.com/openx/www/admin/' hut i'm getting this error
No route matches "/openx/www/admin/"
Should i add a custom route on my routes.rb file?
No matter what, I'd suggest setting up vhosts so that you can have oxadmin.mydomain.com go to /path/to/openx/www/admin and have oxdelivery.mydomain.com go to /path/to/openx/www/delivery and oximages.mydomain.com go to /path/to/openx/www/images
OX was designed so all files which should be public are in the 'www' folder - setting it up like above keeps only the www files publicly available while also separating your admin, delivery, and image domains

Advice request: Serve local folder through rails (or not?)

The task: Serve the files located in a local folder on the server to clients over http/80.
In the end, I plan to emulate the folder on the client but that doesn't concern my question.
So, there is an existing Rails app (rest based/xml) on that server that the clients would use in conjunction with these files.
I don't need any logic to be done on the files either on upload or download so I ask myself:
Do I need to involve my Rails app in serving these files?
Shouldn't the webserver solely handle the link between the local files and the clients?
Would this new Rails Metal or Rack integration be part of the solution? (not familiar with either)
I guess the important thing here is http over port 80.
Thanks for any pointers or advice on the matter,
cheers, Max
I know that with the good time investment I could look all this up for a couple of hours and figure it out but I am very very busy saves me alot of time.
Apache? Just add another <Directory> section to your configuration for the Rails app:
Alias /static-files /path/to/the/static-files
<Directory /path/to/the/static-files>
Order allow, deny
Allow from all
# whatever else you need, Options, AllowOverride, etc.
</Directory>
Put the files in a subdirectory of the "public" directory - as with stylesheets and javascripts
you can use X-Sendfile if you are using Apache or Lighty (see this blog post). Nginx supports X-Accel-Redirect. Both of these approaches will let your web server directly send the file without involving your rails app.

Resources