RAILS_ROOT require?
Yes, you should require the environment.rb:
require File.dirname(__FILE__) + '/../config/environment.rb'
puts RAILS_ROOT
And Rails.root
instead.
Rails.root in lib directory
RAILS_ROOT is deprecated, try Rails.root instead.
ruby-1.9.2-p180 :004 > File.expand_path(File.dirname(__FILE__) + '/config/environment.rb')
=> "/home/lpeabody/Documents/ccom_work/dataserver31/config/environment.rb"
ruby-1.9.2-p180 :005 > require File.expand_path(File.dirname(__FILE__) + '/config/environment.rb')
=> true
ruby-1.9.2-p180 :006 > Rails.root
=> #<Pathname:/home/lpeabody/Documents/ccom_work/dataserver31>
ruby-1.9.2-p180 :007 > RAILS_ROOT
NameError: uninitialized constant RAILS_ROOT
from (irb):7
from /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
Rails Root directory path?
In Rails 3 and newer:
Rails.root
which returns a Pathname
object. If you want a string you have to add .to_s
. If you want another path in your Rails app, you can use join
like this:
Rails.root.join('app', 'assets', 'images', 'logo.png')
In Rails 2 you can use the RAILS_ROOT
constant, which is a string.
Unable to locate where deprecated RAILS_ROOT is used
One of your gems is using RAILS_ROOT
in its initialization code.
From your app's bundle directory, try: grep -R RAILS_ROOT .
(If you are using RVM, the bundle directory will be in ~/.rvm/gems
; otherwise it may be .bundle
within your app's main directory.)
Where does RAILS_ROOT (Rails.root) come from?
Change the symlink so that /var/www/application points to /home/user/application/public
Then just change RailsBaseURI to RackBaseURI and undo your changes to spawn_manager.rb
Previous discussion assumed single application.
<Directory /var/www/application/public>
Order Allow,Deny
Allow from all
Options -MultiViews
</Directory>
See the Apache Phusion documentation.
You need to add DocumentRoot and append /public to your Directory config and undo your changes to spawn_manager.rb.
As you noticed, the app_root is one directory up from what is specified.. The parent directory of /home/user/application/public is /home/user/application which is the Rails root.
You want RackBaseURI instead of RailsBaseURI for Rails > 3
The reasoning behind this is so that Apache serves the static assets (which are in the public directory) and then if that isn't present Passenger routes the request to the Rails app.
Ruby on Rails file authorization under RAILS_ROOT/public
If you need access control for your files you don't want to serve them from your public folder. Your public folder is server either by ActionDispatch::StaticFile
or directly by your web server - neither of which provide the kind of access controll you want.
Instead you would create a controller which serves up the files:
class FilesController < ActionController::Metal
before_action :authenticate! # you need to implement this
before_action :authorize! # you need to implement this
# GET /files/:filename
def show
path = Rails.root.join(
'uploads', # can be any directory you want really
# avoids a malicous user being able to use for example '../../secret/password'
ActiveStorage::Filename.new(params[:file_name]).sanitized
)
if File.exist?(path)
send_file path
else
head :not_found
end
end
end
RAILS_ROOT Not Correct When Launching Unicorn with Capistrano deploy on rbenv
From Deefour's comment, I switched from using unicorn_rails to unicorn executable.
Related Topics
Add Current Time Before Log Message
Naming Conventions for Boolean Attributes
How to Export a Rails Model to JSON Schema
How to Find Out the Starting Point for Each Match in Ruby
Is There a Shorthand If (Without Else) Statement in Ruby on Rails
Simple_Form with Bootstrap Check Box
Approach for Installing System Service Implemented as Ruby Gem
Sending Http Post Request in Ruby by Net::Http
Is There a Definitive Reference Document for Ruby Syntax
How to Install and Use Slim Template Engine with Middleman
Rails 3:Do I Need to Give Return True in a Before_Save Callback for an Object.Save to Work
Why Is Rack Response Body an Array Not a String
Where Do You Put CSS Files in a Rails App Directory
How Do Enumerators Work in Ruby 1.9.1
Jekyll Templates Using Django-Like Liquid Blocks/Inheritance