I have application on Rails 3. Everything works just fine, but as we know best performance should be on Production mode.
When I set environment as Production in Justhost control panel and in environment.rb file
with
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Darbs::Application.initialize!
ENV['RAILS_ENV'] ||= 'production'
And touch tmp/restart.txt
It gives me error:
Ruby (Rack) application could not be started
Error message:
Admin is not a class
And when I check current environment with Rail.env.production? it returns false.
I tried several restarts and so on without success.
in production log file I get Connecting to database specified by database.yml
It means some problem with connecting with specified database?
Any suggestions ?
Thanks.
Related
New rails project.
Rails 5.0.2
Sidekiq 4.2.10
I ran rails g sidekiq:worker deposit_collector and then filled out the code I needed inside the perform method.
To test I logged into the rails console and typed: DepositCollector.perform_async and I get the error:
NameError: uninitialized constant DepositCollectorWorker
The worker is where it should be in the app/workers/ folder. I've used sidekiq on several projects before and have never run into this.
By default, Rails will include all subdirectories of the app folder in the autoload paths list. You can review the list of autoload paths in the console with:
puts ActiveSupport::Dependencies.autoload_paths
But Rails only looks for these paths at boot time. So when you add a new folder, like app/workers, it is not enough to restart the Rails console. You need to both exit the Rails console and stop the Spring Application Preloader with:
spring stop
Then start up the Rails console again and the files in the app/workers folder will load properly.
I didn't have spring installed so I took the lazy approach and turned on eager loading in my config/environments/development.rb file:
config.eager_load = true
and then turned it back to false after restarting my server.
Using capistrano I'm deploying my Rails 4 app under the environment name "staging". When I ssh onto the server and run rails console, any ActiveRecord queries I do come up with no such table. So I check my Rails.env and sure enough it reads development instead of staging. But even running rails console staging, it does set Rails.env to "staging", but still the ActiveRecord queries say no such table. The app itself is running fine (under Apache and Passenger), but for some reason the rails console is unable to connect to the db.
I've reverted back to when I knew it was working and am still seeing the error, which tells me it is a configuration change i must've made on the server as opposed to a change to the rails app code or capistrano deploy config.
OK, tracked down the answer myself. The RAILS_ENV was originally being set to staging in /etc/environment -- but a while ago this file was removed during some debugging, and not restored.
What does still surprise me is that
rails console staging
does not have the same effect as
export RAILS_ENV=staging
rails console
anyhow, sorted.
I am pretty much brand new to RoR and such.
I am following a video tutorial to build my own web-based app, and I got to the step:
git push heroku master
When in git bash, it was coming up with an error that claimed it couldn't compile ruby. Now, it says it is launched and deployed, but there is still the same error on the page for my app, http://infinite-mountain-6131.herokuapp.com/
Any ideas?? I can add files if needed.
Requested file(s):
app/config/application.rb from my comment
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# config/application.rb
config.assets.initialize_on_precompile = false
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Myrubyblog
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end
Line 6 that was mentioned in my error is the config.assets.initialize which I put in there with line 5 as suggested to fix my problem.
This is what happens when I run the migrate as suggested (heroku run rake db:migrate)
Running 'rake db:migrate' attached to terminal... up, run.6274
rake aborted!
NameError: undefined local variable or method 'config' for main:Object
/app/config/application.rb:6:in '<top <required>>'
/app/Rakefile:4:in 'require'
/app/Rakefile:4:in '<top <required>'
<See full trace by running task with --trace>
As a rule, there are two types of error you can get when hosting a Rails app on Heroku:
Heroku Error
-
Rails Error
--
Error
The difference between the two is important - rails errors will only occur if your operating environment is actually "running" your Rails application. Heroku errors will occur if your operating environment / Heroku will not load correctly
The problem you have is definitely a Heroku issue - one which is typically created by a lack of db connectivity. The way to fix this issue is to ensure your application has all the necessities to run - most notably the correct db
You'll be best using the following:
$ heroku run rake db:migrate
However, I appreciate this won't be the only issue you'll have
Heroku Deployment
As you've said you're a "beginner" to ROR, let me give you some ideas
Firstly, when you write a question on here, it helps to divulge as much information as possible - typically from the logs, or any other specific error handling mechanism
Secondly, you want to ensure that everything required to get your application running has been achieved. Most notably, when you mention Heroku cannot compile the Ruby application, you'll need to provide information on why this is the case -- there'll probably be a gem conflict (SQLite3) or similar
Thirdly, you need to ensure you have migrated your database. This is the single biggest reason why "Heroku errors" appear - deploying your Rails app doesn't mean the migrations you made locally will persist - you need to ensure you have the db updated as you require, which can be done as follows:
$ heroku run rake db:migrate
Does anyone know what the contents of config.ru should be for a Rails 2.3.18 app in production to run on Passenger/Unicorn/Puma?
So far I've got:
# Require your environment file to bootstrap Rails
require ::File.dirname(__FILE__) + '/config/environment'
# Dispatch the request
run ActionController::Dispatcher.new
but it's loading development instead of the correct production environment.
It turns out this is a perfect config.ru.
The real problem is that Unicorn's -E parameter sets RACK_ENV and Rails 2.3.18 needs RAILS_ENV in order to correctly detect the environment.
So, at the top of config/environment.rb, I've set ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] and this is working just great.
How to set Rails application to Production mode? I'm using capistrano
On my server, doing a rails console shows its in development mode (puts RAILS_ENV)
It really depends on the software you're using to serve your production site. For example, Passenger sets the environment to production by default.
You should investigate the configuration for your production application server.
Make sure you include
ENV['RAILS_ENV'] ||= 'production'
in your environment.rb file.