Ruby on Rails Gem or Plugin Rails Version - ruby-on-rails

I am working on a rails 2.3.4 application that I am trying to port over to run with IIS and Helicon Zoo. The problem I am encountering is an exception in:
c:\Zoo\Workers\ruby\lib\app.rb
where the following exception is getting raised on line ~32:
STDERR
[tid-21079944] Only Rails 2.3.x and Rails 3.x are currently supported. (RuntimeError)
C:/Zoo/Workers/ruby/lib/app.rb:33:in `build_app'
C:/Zoo/Workers/ruby/lib/app.rb:16:in `initialize'
C:/Zoo/Workers/ruby/lib/worker.rb:4:in `new'
C:/Zoo/Workers/ruby/lib/worker.rb:4:in `initialize'
C:/Zoo/Workers/ruby/zoorack.rb:30:in `new'
C:/Zoo/Workers/ruby/zoorack.rb:30
This is puzzling for me since the version of rails this application was running on previously was 2.3.4. The working hypothesis I am going on is that rails somehow can run plugins in a legacy mode? Does this make sense? I am thinking that Helicon Zoo does not support rolling back in this legacy mode prior to 2.3.4.
I hacked up the app.rb file a bit to get at the rails version.
Invoking: Rails.version.to_s
I am getting: 2.2.2
Searching the code base for '2.2.2' I see that this project depends on an actionpack lib version 2.2.2.
Further, do rails plugin versions typically follow the 'rails' version they depend on?
Is it possible to run plugins that depend on an older 'rails' version than what they run with?

The problem here was that I had installed rails 2.3.4 with gem but had copied a 2.2.2 version of rails with the project to the Helicon Zoo web root directory. The actionpack lib is part of rails. I was thinking it was a separate library.

Related

Use an older version of Rails with Rails 6 installed

Thank you this community for getting me started on the right path. Specifying rails version to use when creating a new application gets me close, but the differing ruby version is what is throwing me off. I'm running into an error after running rails new that I'm not sure where to begin to resolve it. I gather from the error that my command is missing a parameter, but I can't determine what it is.
Any advice?
I would like to create a rails 5.2.6 project and I'm finding consistent responses elsewhere indicating that my approach to getting a rails project created with a specific version is to:
install the rails gem with gem install rails -v 5.2.6
create a new rails project, specifying the rails version with rails _5.2.6 new appName
I think I'm on to it. Did a specific google search for compatibility of Ruby 3 with Rails 5 and appears this is the likely problem.
I've now run 'rvm install 2.7.4' then 'rvm use 2.7.4' but still seems to be using ruby 3 in the command. The new error:
user#ubuntudev:~/railsprojects$ rails _5.2.6_ new rpapitest
/home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:281:in `find_spec_for_exe': can't find gem railties (= 5.2.6) with executable rails (Gem::GemNotFoundException)
from /home/user/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems.rb:300:in `activate_bin_path'
from /home/user/.rbenv/versions/3.0.0/bin/rails:23:in `<main>'
Try with rbenv global 2.7.4 if you have rbenv installed

Upgrading from Rails 2 to 3: undefined method use_standard_json_time_format

I am trying to upgrade Rails from 2.3 to 3.1. I watched the upgrade video from Railscast but I am having some difficulties.
Steps I followed:
Create a separate Rails 3 branch from stable branch.
Update and reload RVM to the latest version.
gem install rails -v 3.0.20.
rails upgrade check and rails upgrade backup using Rails upgrade plugin.
rails new . --skip-active-record
When I start the server I am getting this error:
initializers/new_rails_defaults.rb:13:in `<top (required)>': undefined method `use_standard_json_time_format=' for ActiveSupport:Module (NoMethodError)
Can anyone please help?
The default for use_standard_json_time_format changed between Rails 3.0.20 and 3.1.0 from false to true, so depending which version you're aiming for (your question mentions both), you might be able to drop the configuration.
If you're cherry-picking ActiveSupport modules, make sure you've required ActiveSupport::JSON::Encoding, which defines the method.
require 'active_support'
require 'active_support/json/encoding'
And since ActiveSupport.use_standard_json_time_format is just delegating to ActiveSupport::JSON::Encoding, you can also try calling it directly on the latter.
ActiveSupport::JSON::Encoding.use_standard_json_time_format = true

How can I ensure Ruby is using the Rack gem that's vendored in my Rails app?

My Rails 2.3.x application is failing, because it's using the wrong version of Rack (one with a bug). There are two versions of Rack on my system, a vendored one (the right version) and a system one, installed via apt-get.
Why is it using the wrong version? This is particularly puzzling me because the vendored version is being correctly used earlier in the call stack. And how I can make it use the right version?
Here's an excerpt from the stack trace I'm getting when the application fails:
/usr/lib/ruby/vendor_ruby/rack/utils.rb:202:in `set_cookie_header!'
/home/alaveteli/vendor/gems/rack-1.1.0/lib/rack/response.rb:57:in `set_cookie'
/home/alaveteli/vendor/rails/actionpack/lib/action_controller/response.rb:181:in `set_cookie'
Note that line 2 is using the vendored Rack, but line 1 is using the system Rack. (Line 57 of response.rb calls a module from Rack, thus: Utils.set_cookie_header!(header, key, value).)
My $LOAD_PATH is as I believe it should be, with the vendored gems coming before the system ones.
Yes, I am planning to migrate to using Bundler soonish.
Try using rbenv and ruby-build. It's a sane ruby version management system (unlike rvm which is insane). You get a ruby version per folder and all it's gems. When I have alaveteli issues, I usually ask them on the dev mailing list. I run the Romanian alaveteli.

Rails gem error while trying to upgrade rails project to rails 3

While trying to upgrade rails project from rails 2.3.5 to rails 3.0.3 i get following error:-
/opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems.rb:230:in
activate': can't activate rails (=
2.3.5, runtime) for [], already activated rails-3.0.3 for []
(Gem::LoadError) from
/opt/ruby-enterprise-1.8.7-2010.01/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:35:in
require' from
./script/../config/boot.rb:54:in
load_initializer' from
./script/../config/boot.rb:38:inrun'
from ./script/../config/boot.rb:11:in
boot!' from
./script/../config/boot.rb:109 from
script/server:2:inrequire' from
script/server:2
The application is using ruby-enterprise-1.8.7. Can any one point out why rails 2.3.5 is being loaded, even though rails 3.0.3 is specified.
Thanks in advance,
Anubhaw
How did you upgrade? It looks like your config/boot.rb is unchanged, which means it will attempt to load Rails 2.3.5. There are significant changes in the files in the config directory between Rails 2 and 3.
In my experience it's easier to create a new Rails 3 application, and copy all functionality (models, controllers, views, tests, ...) to this new application. It'll save you trouble and can be done very quickly.

Problem deploying frozen Rails app - "could not find RubyGem rack"

I have a rails app which I develop on Windows with Rails 2.3.5, using sqlite3 as my database engine, and the internal Mongrel server as my webserver.
I deploy this app to a hosted Linux machine running Rails 2.1.0, using Postgres as my database, and Apache (calling dispatch.cgi) as my webserver. I do not have permissions to update the native Ruby or Rails installations, or to install gems natively.
In order to make my deployment easier (I thought...), I have taken a branch of my code-base for the deployed system. On this branch, I have updated database.yml to refer to postgres and run rake rails:freeze:gems and rake gems:unpack:dependencies. I have then exported this branch to my production server.
When I try to view my app on the production server, I get the error:
Application error
Rails application failed to start properly"
Checking the Apache error logs, I see the following:
./../config/../vendor/rails/railties/lib/initializer.rb:271:in `require_frameworks': Could not find RubyGem rack (~> 1.0.1) (RuntimeError)
from ./../config/../vendor/rails/railties/lib/initializer.rb:134:in `process'
from ./../config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
from ./../config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
from ./../config/environment.rb:9
from dispatch.cgi:5:in `require'
from dispatch.cgi:5
I'm confused. If Rack is required, why wasn't it included by gems:unpack? How can I get this working?
(If it's relevant, vendor$ find . -name rack* gives the following:
./rails/railties/lib/rails/rack
./rails/railties/lib/rails/rack.rb
./rails/railties/lib/rails/.svn/text-base/rack.rb.svn-base
./rails/actionpack/test/controller/rack_test.rb
./rails/actionpack/test/controller/.svn/text-base/rack_test.rb.svn-base
./rails/actionpack/lib/action_controller/rack_lint_patch.rb
./rails/actionpack/lib/action_controller/.svn/text-base/rack_lint_patch.rb.svn-base
)
Rack isn't included because it is a framework gem. To vendor this gem you can manually unpack it into vendor/gems like this:
cd vendor/gems; gem unpack rack -v="1.0.1"
You could also start using bundler to manage your dependencies, as Rails now does by default in version three to avoid problems like the one you're currently experiencing.
Your first problem is that Rails 2.1.0 does not use Rack as a middle layer.
You also need to change the rails version in the config/environment.rb file.
Also, depending on the other gems you have used, you may need to go back to a stable version that works with 2.1.0.
Personally, I would install 2.1.0 on my local machine create a new app with that rails version, copy the app folder over from the 2.3.5 project (and of course your unit tests and public folder, etc, and see if you can get it to run under 2.1.0 on your local machine, substituting gems as you go that are failing in the backtrace on the server log or in the browser. This will be much easier than running in production mode and looking at apache logs. Presuming that you have good unit tests that render all your views and flex your model code, then you should flush out any methods you have used that were added since 2.1.0 that are not supported in the older versions of Rails pretty quickly.

Resources