After upgrade to Rails4 - ruby-on-rails

After Upgrade to Rails4 I am getting warning below how can i fix that
.../gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: already initialized constant #<Module:0xbc58784>::AttrNames
.../gems/activerecord-4.0.0/lib/active_record/core.rb:103: warning: previous definition of AttrNames was here
Please Help Me.
My Functionality is working is fine but I don't want warning in my app so how can i fix that.

This is probably caused by an old gem. For example an old version of ActiveAdmin caused similar warnings. Many old gems are not fully compatible with Rails 4.
To update gems run bundle update and make sure that in the Gemfile there are no old versions specified.

Related

Warnings when upgrading application from Rails 5 to Rails 7

with a recent upgrade to rails 7.0.2 from rails 5.2, when ever i start a rails console or a rails server on dev mode i see these warnings
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/digest-3.1.0/lib/digest.rb:20: warning: already initialized constant Digest::REQUIRE_MUTEX
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/digest.rb:6: warning: previous definition of REQUIRE_MUTEX was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:66: warning: already initialized constant Net::ProtocRetryError
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:68: warning: previous definition of ProtocRetryError was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:206: warning: already initialized constant Net::BufferedIO::BUFSIZE
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:208: warning: previous definition of BUFSIZE was here
/Users/opensource/.rvm/rubies/ruby-2.7.4/lib/ruby/2.7.0/net/protocol.rb:503: warning: already initialized constant Net::NetPrivate::Socket
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/net-protocol-0.1.3/lib/net/protocol.rb:504: warning: previous definition of Socket was here
/Users/opensource/.rvm/gems/ruby-2.7.4/gems/apipie-rails-0.7.0/lib/apipie/extractor/recorder.rb:163: warning: Skipping set of ruby2_keywords flag for process (method accepts keywords or method
For what's its worth the warnings are not present when the application is on Rails 7.0 but only appear when the application is upgraded to Rails 7.0.2
I upgraded rails as per the guide
5.2 -> 6.0 -> 6.1 -> 7.0 -> 7.0.2
May be i missed something, anyways I could fix these? probably these would go away with a ruby / rails subsequent upgrade?
Thanks.
Rails 7.0.1 added some gem dependencies for standard lib stuff that would get removed in ruby 3.0. This unfortunately causes issue with ruby 2.7.6. You can get around this in several ways. Upgrading ruby will also upgrade bundler which fixes the issue. Upgrading bundler without ruby also works but I don't recommend it (better to point to the system version). A more conservative workaround is find the gems that are causing issues and list them on the top of your Gemfile. In my case I had to make sure that the gem version was the same as the default ruby gem version. For example, I had to make the Gemfile have gem "uri", "0.10.0". A good way to debug what is causing these is put this at the top of your Gemfile:
Warning.module_eval do
alias_method :original_warn, :warn
def warn(msg)
if msg.match?(/already initialized constant/)
raise msg
else
original_warn(msg)
end
end
end
That way you get a stacktrace of the places that are requiring stdlib files that also have a conflicting rubygem.
It looks like these are all constants defined in dependency code gems. Running bundle clean --force or updating dependencies with bundle update and then running the bundle clean --force has worked for some when experiencing this issue.

Rails Generate model error in Ruby on Rails

I am building a new RoR app and i had tried to create a new model like below.
rails generate model Pic title:string description:text
But I keep on getting these errors always and I tried installing many methods like installing gems ,updated the gems etc.
P.S : I am trying install the older version of the gems. Is that creating a problem?
But none of it gave me the results. Please help me with this.
P.P.S : I am an absolute beginner to ruby. So please help me by giving solution with good reason. Thanks in Advance.
Hi seems like you have issues with your simple_form gem,try to remove from gem file and add gem 'simple_form' and run bundle install after this step run rails generate simple_form:install for creating config file for simple form.
Try this it may help you out.
As #Navneet pointed out generating a config file can also be used for configuration and it also works pretty well.
Another thing i found was , Here the gems used were older version. That created a compatibility issue(since it was not configured accordingly). So by replacing the gems with current version or stable ones , you can get rid of this problem.
Go to rubygems.org
Search for the gems and check whether its the latest version
If not, Replace the line of corresponding gem in Gemfile with newest one.

How do I avoid the circular argument reference warning in activesupport

How do I avoid the circular argument reference warning in activesupport. Happens on ruby 2.2.0
/home/ec2-user/apps/foo_prod/shared/bundle/ruby/2.2.0/gems/activesupport-3.2.21/lib/active_support/values/time_zone.rb:270: warning: circular argument reference - now
/home/ec2-user/apps/foo_prod/shared/bundle/ruby/2.2.0/gems/ruby-ole-1.2.11.7/lib/ole/types/base.rb:265: warning: duplicated key at line 266 ignored: 4095
Use Rails 3.2.22
gem 'rails', '3.2.22'
OR
warning fixes in version 1.2.11.8:
bundle update ruby-ole
This is an issue of Active Support and has been fixed with these two commits:
https://github.com/rails/rails/commit/8fd52705eda6a2cd7e9a8a5bc723fa094e359eb7
https://github.com/rails/rails/commit/3a30b12c774dfaa72acfe520e823374131631ea9
Unfortunately, these commits have been never included into the 3.2 releases,
because the current last release (v3.2.21) was out on 18 Nov 2014
and after that these commits were merged.
If you don't want to see this warning message definitely, you should change
your Gemfile like this:
# gem 'rails', '3.2.21'
gem 'rails', git: 'https://github.com/rails/rails.git', branch: '3-2-stable'
Otherwise, you should downgrade ruby to 2.1 or wait the release of v3.2.22,
which won't come until a grave security hole is found.
After all, there is no easy way to avoid this issue. Changing Gemfile
for such a trivial annoyance may be an overreaction in my view.
It will delay your deployment process quite a lot.
I was not using compass in my application Based on this post here I upped my Rails version from 4.1.1 to 4.1.9 which worked.
This is compass issue here. They haven't release new version yet so you may need to wait for it.
here is what i did to resolve that, i had the latest ruby and the gems are not compatible with that, so after having a fight for nearly a day i switched to older ruby version using rvm
from ruby-2.2.1 to ruby-2.0.0 ,
again this is not an issue with ruby version but incompatibility with gems,try and have good luck with that.
Well, Here is a solution to this:
Try doing all these changes in your .rbenv/.rvm folder and change in these files:
https://github.com/tmm1/rails/commit/8fd52705eda6a2cd7e9a8a5bc723fa094e359eb7
Hypothetically, updating to Rails 4.2.0 - which you should be able to do via the following commands - should fix this error, although it hasn't worked for me:
rvm use ruby-2.2.0#rails4.2 --create
gem install rails
rails -v
I'm getting the same "circular argument error" message as well (I posted more about my failed attempts to fix it here, will update if I find an answer: Rails gem update not working (version 4.1.1 to 4.2.0) as a solution to "warning: circular argument reference" error).
I altered the time_zone.rb file, instead of now=now, I entered now=Time.now and problem solved.
I ran into the same issue as well, yo can sue the following steps to resolve it (worked for me).
$ gem uninstall compass
$ gem update --system
$ gem install compass

Is my rvm directory structure in a weird state?

I don't really know where to turn on this one. Due to an unfortunate situation, I'm in the middle of a rebase which is trying to add ember to a project while upgrading to rails 4.1 and ruby 2.1.1 at the same time (the rails and ruby upgrades were merged into the project while I was on the add ember branch). I'm getting all sorts of dependency errors when trying to get a rails server up.
Some of the errors included:
bin/rails:8: warning: already initialized constant APP_PATH
/home/amax/git/forever/bin/rails:8: warning: previous definition of APP_PATH was here
cannot load such file -- websocket/driver
cannot load such file -- active_model_serializers
One thing I noticed was that my rvm path has 2.1.1 and 2.1.0 in it which I'm guessing is a bad sign. I'm thinking it may be loading old gems
root/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems.....
Does anyone know if this could cause problems and any suggestions on a possible remedy?
The errors seemed to change every time and it seemed to be the fault of an irredeemably screwed up gemfile.lock that I caused during the rebase.
I started from a new branch with rails 4.1.1, added ember to it and then copied and pasted that working gemfile.lock over the broken one which resolved all of the issues. If you get into a similar situation I think it may be worth a try to blast away your gemfile and gemfile.lock and recreate them in a stable environment

problems updating to new version of prawn on production server with bundler

I have updated my code etc to work with the 0.10.2 version and its all
working in development.
When i deployed to my production server and done a bundle install i
still get this errors?
git://github.com/sandal/prawn (at 0.10.2) is not checked out. Please
run bundle install (Bundler::GitError)
I then run bundle install again and get this error
/usr/local/rvm/gems/ruby-1.8.7-p302/bundler/gems/prawn-89ba0ebf7ac3/
prawn.gemspec:2: warning: already initialized constant PRAWN_VERSION
Can anyone help with this PLEASE ?
thanks alot
rick
I had similar issues and resolved it by removing the prawn submodules in git.

Resources