1 error prohibited this {{model}} from being saved - ruby-on-rails

Rails is showing the validation messages on the page as such:
1 error prohibited this {{model}} from being saved
There were problems with the following fields:
{{attribute}} {{message}}
Wanting it to show the model names not these these brackets.
How do I fix it and why's it doing this?

This is a problem with internationalization in rails. One solution that has worked for some is to downgrade the internationalization gem from 0.5.0 to 0.4.2, like so:
sudo gem uninstall i18n
sudo gem install i18n -v 0.4.2
Of course, if you're using RVM to manage your gems, you don't need sudo in the commands above.

The proper solution involves using bundler to manage your gems instead of using the system defaults and the old Rails 2.x method of embedding it into environment.rb. Bundler segregates your application gems from your system gems properly and removes the problems that occur when using i18n versions 0.4.2 and 0.5 along with Rails 2.x and 3.x.
Steps:
Setup bundler for your Rails 2.3 app
http://gembundler.com/rails23.html
In your Gemfile, just completely leave out i18t.
Run 'bundle'
Note: If you do need i18n, just specify the correct version in the Gemfile. Bundler properly segregates your app's gems from your system gems so there will never be the strange behaviors of having both 0.4.2 and 0.5 installed on your system.

if you want to leave both gems installed, another solution is to create config/preinitializers.rb and add the line
gem 'i18n', '0.4.2'

While using Rails 2.3.5, even with config/preinitializers.rb containing
gem 'i18n', '0.4.2
and environment.rb containing
config.gem "i18n", :version => '0.4.2'
I had to uninstall version 0.5.0 of the i18n gem to make this work.

Related

downgrading rails 4 to 3.2

I have the Rails 4.0.0.beta1 installed but I need downgrade to Rails 3.2.13.
I've used gem install rails 3.2 but Rails continues as 4.0.0.beta1.
I searched existing doubts and try to follow the answers however none worked for me.
Think this is a simple doubt and I need to solve.
This answer my question: How to set default rails version for a project?
You have the same problem as listed here.
Here is what worked for me, and should also for you. It's a more general solution that works regardless of your specific version of the Rails beta. Please note that in order to shift back to 3.2.13 (or whatever version you'd like to go back to), you must remove Railties as well as Rails.
Just do:
gem uninstall rails
Then, select the version of Rails 4 you have and delete it.
Then, do:
gem uninstall railties
And do the same thing.
When I uninstalled the Rails 4 version of railties, it told me that dependencies for a couple gems (coffee-rails and sass-rails) wouldn't be met. So I just did the same thing with both of them as I did above, and deleted their Rails 4 versions as well (for example, for sass-rails, I had a version installed called sass-rails-4.0.0.rc1).
And done! The terminal should list 3.2.13 as your current Rails version.
Unless you're using bundle exec, Rubygems will always use the latest installed version of a gem. You need to uninstall the version you don't want.
gem uninstall rails --version 4.0.0.beta1
The answers to gem uninstall rails --version xxx should remove the rails gem just fine.
However, in the event you want or need to have multiple versions of rails available simultaneously, you can use bundler to load the correct versions of gems (as intended).
$ bundle exec rails in the project directory that lists the version of rails in the Gemfile should let you load the required gems without conflict.
Additionally, rvm and its gemset feature could also let you accomplish the same goal without needing to wrap everything with a bundle exec
Rails will use the version specified in Gemfile:
gem "rails", "4.0.0.beta1"
Replace it with the version you'd like to use instead:
gem "rails", "~> 3.2.0"
Of course, you will also need to change your code and config to use the old Rails API.
I had the same problem with Rails 4.0.0 final version. To check what is currently installed you can run the following:
>pik gem list
Then I checked the rails versions. It showed rails 3.2.14 (what I wanted) with railties 4.0.0, 4.0.0.rc2 and 3.2.14.
I then ran
>gem uninstall railties
and uninstalled all other versions except 3.2.14 and now it works well. The problem was that when Rails 3.2 installation is called, the latest (or all) versions of railties is installed.
If you have other versions of rails other tan the one you want, you can removed them with
>gem uninstall rails
and remove the versions of rails you do not want to have.
Try the following in your console. It will update or install rails to the specified version.
gem update rails 3.2.13

Why prawnto gem installs rails 3.x when there is already a rails 2.x?

I have rails (2.3.5) and prawn (0.12.0) installed. When I install prawnto, gem installs rails version 3.2.6 also.
The dependency of prawnto is:
prawn >= 0
rails >= 2.1
Why gem install Rails 3.x when the prawnto dependency is already there?
tl;dr Use Bundler. It rocks.
Alright, this is basically down to how dependency resolution works in RubyGems. If you're not terribly familiar with it, get up to speed real quick like with the Primer panel from this XKCD comic. RubyGems dependency management and the Primer storyline are very similar in terms of complexity.
When a gem specifies a dependency of, say rails >= 2.1, when you go to install that gem, RubyGems conveniently ignores all the gems that you've currently got installed and then queries the web API to find the absolute latest version of Rails that's greater than or equal to 2.1.
It will find, as of this writing, version 3.2.6, and so will dutifully install that version of Rails because it fits the dependency requirements. It will also install every single dependency of Rails, and their dependencies, and the sub-sub-sub-sub-dependencies all the way down until there's not a gem left without a dependency installed.
I won't go into exactly how that works because it makes my vision go blurry when I think about it.
Now, if you were using something that's not pure-RubyGems such as Bundler, you'd be able to have a Gemfile like this:
source 'http://rubygems.org'
gem 'rails', '2.3.4'
gem 'prawnto', '0.1.1'
And then run bundle install and then something magical will happen. Bundler will figure out the dependencies for all the gems specified in the Gemfile, as well as the gems that they depend on, and then install only those gems.
This means that if you have prawnto wanting Rails >= 2.1, it won't install 3.2.6 because there's another dependency saying that Rails must precisely be 2.3.4. So therefore Rails 2.3.4 will be installed.
If you have conflicting versions, with a gem A specifying a dependency on gem B of ~> 1.0, but then gem C specifying a dependency that gem B must be '= 0.5.0', Bundler won't be very happy and will raise an error because the dependencies can't be resolved.
I'd really recommend using Bundler for all your Rails projects. Even those that are running on Rails 2. There's a page on the Bundler website which will get you started with a Rails 2.3 project and Bundler.

rake gems:install, how do I prevent a particular gem from installing?

one of the gems that one of my required gems installs is i18n-0.5.0.... which causes problems with my other gems...
but i18n-0.4.2 works.... but I can't have both, because the app favors the more recent i18n gem.
this is how I require the proper i18n:
config.gem 'i18n', :version => '0.4.2'
no greater than.
so.. two qusetions, why does it prefer the newer one, when I specify the older one?
how do I prevent 0.5 from installing?
I'm not sure of that but your problem could come from the 0.5.0 version of the gem wich is still install on your environment. Try a gem list I18n to see all the versions and if the 0.5.0 is here you can try :
gem uninstall I18n 0.5.0
This version was installed before and never remove. But with you new config it will not be re-installed with the rake gem:install command.

Ruby on Rails, xmpp4r 0.5 and no such file to load -- xmpp4r

have ruby 1.8.7, gem 1.3.7 and rails 3.0.6. I wanted to add xmpp4r to my project, but i got error just i require this gem. I'm install this gem using gem install xmpp4r. Installation seems successful.But, why error then appear?
P.S. if in console enter the irb and execute require "xmpp4r" result will be true.
P.S.S. OS is Fedora
Rails 3 uses Bundler to manage gem dependencies. When you start a rails 3 application, bundler sets up the require path to only include those gems you have specified in your Gemfile file, and their dependencies; it's not enough to just have the gem installed on your system.
In order to get this working, simply add this line to your Gemfile:
gem 'xmpp4r'

Rails 3.0.3, rails_admin gem, generator not found

I am getting error installing Rails_admin with rails 3.0.3. Command line log shown below -
C:\rorprj\app>gem uninstall rails_admin
Successfully uninstalled rails_admin-0.0.0
C:\rorprj\app>gem install rails_admin
Temporarily enhancing PATH to include DevKit...
Successfully installed rails_admin-0.0.0 1 gem installed
Installing ri documentation for rails_admin-0.0.0...
Installing RDoc documentation for rails_admin-0.0.0...
C:\rorprj\app>rails generate rails_admin:install_admin
**Could not find generator rails_admin:install_admin.**
C:\rorprj\app>rails -v
Rails 3.0.3
Anything I can do fix this?
Try this
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
Sometimes the actual github repo has an different version. I have it running on 3.0.3 and that is what is in my gemfile.
If you call
rails generate rails_admin
the 'help' returns
*Hello, to install rails_admin into your app you need to ru*n:
rake rails_admin:install
And this works. I just encountered the same problem as you. (Keep in mind that you need to add the gem to the gemfile too)
Did you add this gem to your Gemfile? This file is responsible for loading all gems that your application depends on, and if this gem isn't specified in it then it will not be loaded.

Resources