I'm trying to upgrade the I18n backend of my application to use the database instead of the yml files for internationalization. I'm following the steps found for the I18n-active_record gem found here: https://github.com/svenfuchs/i18n-active_record.
Unfortunately, the aws-s3 gem seems to be conflicting somehow as I can't even start my server or console once I create the locale.rb initializer. Here is a summary of the steps I'm following:
gem "i18n-active_record", "~> 0.0.2"
create new file config/initializers/locale.rb
inside locale.rb
I18n.backend = I18n::Backend::Database.new
restart localhost server to load initializer
Error Message
/Users/user_name/.rvm/gems/ree-1.8.7-2010.02#app/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing': uninitialized constant I18n::Backend::Database (NameError)
...(Several more lines)
Any help or insight would be appreciated!
Great question and great discussion. The answer is contained in a combination of the comments up above, but for those of you who are upgrading to a Rails 3 application, this is a summary of the steps I had to take.
Add this to your Gemfile:
gem 'i18n-active_record', :require => 'i18n/active_record'
Add this to a new config file config/initializers/locale.rb
require 'i18n/backend/active_record'
I18n.backend = I18n::Backend::ActiveRecord.new
Take out any code in application.rb that was previously initializing the record store. This clears the missing content errors. Full instructions are on the Github repo for this backend module which was removed from the core I18n: https://github.com/svenfuchs/i18n-active_record
Although the readme in github says so, I don't think the Database constant is actually defined by the gem. Try
I18n.backend = I18n::Backend::ActiveRecord.new
Related
I've been following this tutorial, to install the ShareMeow gem in my rails app.
After adding the gem to my gem-file and the configuration variables in an initializer I run into this error.
.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/share_meow_client-0.1.3/lib/helpers/configuration.rb:18:in
`<main>': Configuration is not a module (TypeError)
After googling this error, I suspect that I'm getting this error because my rails-app already use 'Configuration' as a class somewhere else in the app?
Any ideas on how I can get around this to use this gem?
You have several options.
You can fork the gem and move Configuration into ShareMeowClient:: namespace. Then use the fork instead of the original gem with gem 'share_meow_client', github: 'you/ShareMeowClient'. You can even send this change upstream.
Alternatively, you can rename Configuration class in your app to something else (e.g. AppConfiguration) so that it doesn't clash with the one from the gem.
Or you can just copy the implementation of image_url method to your app and not use the gem at all. This is what I would prefer. The gem looks like abandonware anyway, last update is 5 years ago. It's only a few lines of code.
I followed this blog. I found one error: I mentioned in environment.rb require ‘contacts’.
When I use this require ‘contacts’ the server never started. When I replace this require ‘contacts’ the server starting but some syntax errors came in URL. How can I import my contacts?
That blog entry predates Rails 3, and thus does not refer to the fact that you must add the following to your Gemfile:
gem 'contacts'
and then run bundle install. As a result of this you do not need to put require 'contacts' anywhere, as Bundler will require it for you.
I'm trying to add ssl to my rails 3.0.7 app using the ssl requirement gem, but when I type
include SslRequirement
into my Application controller, the app fails and I get the following error:
uninitialized constant ApplicationController::SslRequirement
Anybody seen this before?
As my comments on the question indicate, you're using gem 'sslrequirement' in your Gemfile, which is pulling down a fork of a fork of a fork of the original, none of which (the ancestors) are the (according to the original) official repository.
To fix this, you can use the following line in your Gemfile instead (note the underscore):
gem 'ssl_requirement'
Which will pull down the appropriate Gem from https://rubygems.org/gems/ssl_requirement.
I've added the delayed_job gem to my gemfile and installed correctly but when I try to run the following line:
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
I get the error 'uninitialized constant Delayed::Job'
Can somebody explain what i need to do here? I've tried running 'rake jobs:work' beforehand but it also returns the 'uninitialized constant Delayed::Job' error. Additionally, I've added "require 'delayed_job'" to the file (application.rb) without much luck.
If you've upgraded to delayed_job version >=3 you'll need to add this (presuming you're using ActiveRecord):
# Gemfile
gem 'delayed_job_active_record'
Did you follow the installation instructions on the README file? https://github.com/collectiveidea/delayed_job
Add this to your gemfile:
gem 'delayed_job_active_record'
and then run this at the console:
$ rails generate delayed_job:active_record
$ rake db:migrate
You need to create the delayed jobs table in the database (this assumes you're using active record).
For Rails 3, all you need to do is include it in the gemfile, run that code above to create the table and migrate the database, then restart your server and go!
I'm using delayed job within an engine (so the gem is specified in a .gemspec rather than Gemfile) and was getting the same error. I found that I could solve the problem by using:
require 'delayed_job_active_record' # fixes problem
rather than
require 'delayed_job' # doesn't
Just in case, if this is still unanswered, check the below link
http://www.pipetodevnull.com/past/2010/4/14/uninitialized_constant_delayedjob/
edit: Alternative, just upgrade to the latest version - 2.1
i was struggling a while back with the same problem. i was following ryan bates screencast on delayed_job and got the same error 'uninitialized constant Delayed::Job'. In the screencast ryan creates a file called mailing_job.rb(located under lib folder) with the delayed_job perform method inside, which allows you to use the enqueue method. After doing some research i found that rails 3 does not automatically load the lib folder files into your app.(not entirely sure)
Try this
In your controller where you use this:
"Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc"
Try to require the file like this.
require 'mailing_job'
class AssetsController < ApplicationController
def some_method
Delayed::Job.enqueue do_it(), 0, 1.minutes.from_now.getutc
end
end
Version change possibility : if you jump from the 2.1.x to the 3.x version of the gem via a non locked down bundle, you may have a similar issue.
I am attempting to get a gem I installed working in a Rails application. I can require the gem just fine in a Ruby program that I run from the command line using:
require 'nokogiri'
But when I attempt to do the same in one of my Rails controllers it errors saying "no such file to load -- nokogiri".
I tried using the full path to the lib/nokogiri.rb file, but that fails because it cannot find "nokogiri/native".
Better, place the following in your environment.rb file:
Rails::Initializer.run do |config|
...
config.gem :nokogiri
...
end
This will tell Rails that you depend on that particular gem. It also allows you to specify particular versions, and it will automatically keep all your gems synched, or unpack them into vendor/gems if you so wish.
I had a similar error but simply forgot to put the following in my environment.rb file: (note the quoted "nokogiri")
Rails::Initializer.run do |config|
...
config.gem "nokogiri"
...
end
Ok I figured it out. This is going to sound pretty stupid...but oh well...
It turns out I had two installations of ruby on my machine. I use InstantRails to serve my test applications and it comes prepackaged with an installation of ruby. I had another installation however outside of this and it was here that nokogiri had been installed, not in the installation in InstantRails.
In any case they were looking in different spots for the gems.
Try the following
require 'rubygems'
gem 'nokogiri'
If you are on some form of *nix then did you get any errors when you installed the gem, particularly errors stating that the gem was not on the path. This may happen if you have installed the gem as yourself rather than as root and you do not have your personal gem library in your gem path.
If you always install your gems using
sudo gem install some_gem_name
then you should not get that problem.