I have an issue with the following line in the config/application.rb file of my generated spec/dummy rails application:
# railtie requires ...
Bundler.require(*Rails.groups)
require "tm_app_core" # This line should not exists according to rails application.rb template
module Dummy
class Application < Rails::Application
# ...
I am using Rails::Generators::AppGenerator to generate my dummy app. But according to Rails application.rb template it should not have the following line:
require "tm_app_core"
Where does this line comes from?
I'm using Rails 3.2.13. tm_app_core is the name of my root directory (will be different on my CI server for example).
Related
I have an application working in localhost and also heroku. The last time that I pushed the new version to heroku I got an error during heroku db:migrate and did heroku db:push and everything was ok.
I get the following error when executing the App.
/app/.bundle/gems/ruby/1.9.1/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library': uninitialized constant AnswersController::Authentication (NameError)
Here is the relevant code
class AnswersController < ApplicationController
include Authentication
...
Authentication is a module defined in lib:
# encoding: utf-8
require 'base64'
require 'openssl'
module Authentication
...
It is working in localhost but not in heroku.
Any help??
Thanks
Try adding the lib folder to your the config.auto_load path in application.rb
config.autoload_paths += %W(#{config.root}/lib)
Also, take a look at this link.
I'm trying to set up a rails 3.2 app with the new compass-rails gem
https://github.com/Compass/compass-rails
I want to compile the files in the assets folder with the compass watch command—as I want to deploy to heroku, but so far i'm unsuccessful.
The compass-rails gem page states:
Developing with the Compass watcher
When using the Compass watcher to update your stylesheets, your stylesheets are recompiled as soon as you save your Sass files. In this mode, compiled stylesheets will be written to your project's public folder and therefore will be served directly by your project's web server -- superceding the normal rails compilation.
In this mode, rails 3.0 or earlier users will experience a slight speed up by disabling the Sass::Plugin like so:
config.after_initialize do
Sass::Plugin.options[:never_update] = true
end
But i don't get where to put this config options
Any idea?
==EDIT==
I tried to add the config.after_initialize block in my application.rb
require File.expand_path('../boot', __FILE__)
# require 'rails/all'
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
# require "sprockets/railtie"
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module Salsacaribecouk
class Application < Rails::Application
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable the asset pipeline
config.assets.enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
config.after_initialize do
Sass::Plugin.options[:never_update] = true
end
end
end
but when i run the rails server I get an error message:
block in <class:Application>': uninitialized constant Sass::Plugin (NameError)
The config.after_initialize should be put in config\application.rb if you want it to be executed in all environments, or in config\environments\[development|test|production].rb to executed in a specific environment.
I have setup my application configuration for my rails 3.1 application as described here by Ryan Bates.
Problem is I want to use the config in my environment file for username/password for ActionMailer, but Ryan suggests loading the config from an initializer, and they seem to get included after environment.rb. Where is the best place to load the configuration file so it can be accessed by the whole rails application?
Thanks
In that case, this code should go in as a pre-initializer. As of Rails 3, all pre-initialization code needs to go near the top of application.rb, just before the line require 'rails/all'
application.rb:
require File.expand_path('../boot', __FILE__)
# load app_config.yml
require 'yaml'
APP_CONFIG = YAML.load(File.read(File.expand_path('../app_config.yml', __FILE__)))
require 'rails/all'
I'm trying to use rails 3 without any db backend, but it still insists on requiring 'sqlite3' gem when I try to access a page, and throws an error no such file to load -- sqlite3, even though no code in the application requires sqlite, except I left database.yml with its default setting for sqlite3, since removing the content raised other errors. Any idea how I could use rails without any database and avoid said errors? thanks.
(also, I'm familiar with Sinatra - just prefer rails for this project).
Rails 3:
In application.rb, remove the require 'rails/all' line and instead add these lines:
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
Also see Remove ActiveRecord in Rails 3
and look into the Active Model railscast
Rails 3.2.x:
You'll also need to remove/comment out this line in application.rb
config.active_record.whitelist_attributes = true
And remove/comment these two lines from development.rb
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
Rails 2.x:
In config/environment.rb add (or uncomment) the line
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
This will cause Rails not to use those frameworks. (Note the nearly-invisible -= !)
Also, in Rails 3, remove any references to active_record in
config/environments/development.rb
config/environments/test.rb and
config/environments/production.rb such as
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
as well as removing require "rails/all" and adding the require lines in comment 21 (above).
if you are not using a database (this works with Rails 3.1.1)
I'm new to rails and making some sort of noob mistake: I frequently need to count the number of lines in a file, so I'm trying to monkey patch class File like this:
class File
def self.line_count( filename )
%x{wc -l #{filename}}.split.first.to_i
end
end
I saved this to /lib/file_util.rb. I thought that this was supposed to be auto-required, so that I could just use it, but that doesn't work:
$ rails console
>> File.line_count('Gemfile')
NoMethodError: undefined method `line_count' for File:Class
...
So I try to require it manually, no joy:
>> require '<myproj>/lib/file_util.rb' # same result with require 'file_util.rb'
=>nil
But it works if I require it within IRB:
$ irb
>> require '<myproj>/lib/file_util.rb'
=> true
>> File.line_count('Gemfile')
=> 22
I also tried to to add the require to config/application.rb:
...
Bundler.require(:default, Rails.env) if defined?(Bundler)
require 'file_util.rb'
module <myproj>
...
and I get:
$ rails console
<myproj>/config/application.rb:9:in `require': no such file to load -- file_util.rb (LoadError)
What am I doing wrong?
Ok, I seem to have mostly figured it out. Rails doesn't automatically require everything under /lib. It only auto loads when you try to use a new class name that matches a file name in lib. So if I define line_count in class FileUtil instead of File it automatically finds and loads 'file_util.rb'. But patching File and naming the patch file 'file.rb' doesn't work, since the File class is already defined, so Rails doesn't go looking for a definition.
My other problem was that I was trying to do the require too soon in the startup sequence, before Rails had a chance to enhance require to look in its directories. When I added "require 'file_util'" to config/environments/development.rb it works fine.
But this doesn't explain why I can't manually require the file from within rails console.
Monkeypatching classes can be done more easily by adding a file in config/initializers. All of those files are automatically loaded by Rails at startup.
You can call your initializer file anything you want. Try config/initializers/file.rb.