Rails - migrating from 3.0 to 3.1 - ruby-on-rails-3

I wanted to help out a open source project by migrating from 3 to 3.1
But I have never had to migrate a large project before so I am looking for some advise ?
this is the project - https://github.com/locomotivecms/engine
Thanks, Alex

here it is an "almost working" locomotivecms code, migrated on rails 3.1:
https://github.com/lgs/engine/tree/rails-3.1
... it is not ready for pull request,
infact it miss to replace /images/ whith /assets/ in all the relative path ...,
anyway it start and stay up (despite many "DEPRECATION WARNING"), on rails 3.1 server:
lsoave#ubuntu:~/rails/github/engine$ rails s
DEPRECATION WARNING: config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
=> Booting WEBrick
=> Rails 3.1.0.rc4 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-06-22 01:54:34] INFO WEBrick 1.3.1
[2011-06-22 01:54:34] INFO ruby 1.9.2 (2010-12-25) [i686-linux]
[2011-06-22 01:54:34] INFO WEBrick::HTTPServer#start: pid=2948 port=3000
Rails console works fine as well :
lsoave#ubuntu:~/rails/github/engine$ rails c
DEPRECATION WARNING: config.generators in Rails::Railtie is deprecated. Please use config.app_generators instead. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from <top (required)> at /home/lsoave/rails/github/engine/config/application.rb:9)
Loading development environment (Rails 3.1.0.rc4)
ruby-1.9.2-p136 :001 >
This is the guide I followed during my try :
http://davidjrice.co.uk/2011/05/25/how-to-upgrade-a-rails-application-to-version-3-1-0.html
UPDATE:
"Cannot modify SafeBuffer in place" error resolved
UPDATE jun 23 11:
resolved "ArgumentError (wrong number of arguments (4 for 3))" adding options param (the fourth) to set_session into lib/locomotive/session_store.rb b/lib/locomotive/session_store.rb
Thanks to Nicholas Hubbard previous answer.

Reposting from GitHub:
It looks like the new sessions in 3.1 require 4 params:
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb Line 61
def set_session(env, sid, session_data, options)
The store in locomotive only takes three:
https://github.com/lgs/engine/blob/rails-3.1/lib/locomotive/session_store.rb Line 31
def set_session(env, sid, session_data)
Looks like options are being passed also that we are not expecting.

Related

Replace 'alias_method_chain :save_attachments, :pasted_images' in Rails 5.2.3

I've got a Redmine 3.4.4 installation running, which uses Ruby 2.2.5-p319 and Rails 4.2.8. We want to upgrade this to Redmine latest (currently 4.0.4) which requires Rails 5.
I'm running the new server using 4.0.4 using Ruby 2.6.3-p62 and Rails 5.2.3. Overall it's OK, but we have a number of plugins installed we would like to migrate. Many of these have had problems because of deprecations in Rails 5. I've managed to muddle my way through 8 of 9 plugins, even though I've not written Ruby on Rails before, but I'm stuck on the last one and just can't figure it out.
The plugin is the My Page Customization plugin and when I attempt to migrate the database and plugins I get this error:
[centos#redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActivitiesController:Class
Did you mean? alias_method
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:11:in `block in included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `class_eval'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `include'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `block (2 levels) in <top (required)>'
So, it's clear that the deprecated 'alias_method_chain' is the issue here. After some digging I found a lot of references online such as this one which is good and clear, but I just can't get code written that works - I keep getting syntax errors and can't figure out what I'm doing wrong.
This is the original snippet from activities_controller_patch.rb:
module ActivitiesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
helper :issues
helper :queries
alias_method_chain :index, :esi
end
end
We'd like to hang onto this plugin if we can even though it doesn't officially support Redmine 4. I'm hoping someone with better Ruby knowledge will be able to help.
Instead of
alias_method_chain :index, :esi
you'll just use
alias_method :index_without_esi, :index
alias_method :index, :index_with_esi
It was some kind of syntactic sugar.

Rails 5 DEPRECATION WARNING: to_prepare is deprecated

When running rspec tests, I am getting the following deprecation warning
DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1 (use ActiveSupport::Reloader.to_prepare instead) (called from <top (required)> at /Users/Chris/Sites/golf_mentor/config/environment.rb:5)
Line 5 of my environment.rb is just
Rails.application.initialize!
How do I fix the code so this deprecation warning does not occur?
That message for sure is generated because a gem is using that deprecated method.
Maybe with rspec -b you could have more insight about what gem is and update that gem (in the best case that the warning was already solved).
If that doesn't work, another option could be to update your gems until find which one is causing the warning.
The last option is just ignore the warning because is not going to cause you problems until you update your app to rails 5.1 and when that time comes you will know which gem is because it will throw an exception.

Routing error when updating to Rails 3.2.6 or Rspec 2.11.0

After upgrading to Rails 3.2.6 or Rspec 2.11.0, my specs starts to show routing errors like the following:
4) UsersController GET activate activation code not exist
Failure/Error: subject{ get :activate }
ActionController::RoutingError:
No route matches {:controller=>"users", :action=>"activate"}
There is also a after each hook error
An error occurred in an after(:each) hook
RSpec::Mocks::MockExpectationError: (#<EmailSubscriber[...]>).update_attributes({:enable=>true})
expected: 1 time
received: 0 times
occurred at [...]/spec/controllers/users_controller_spec.rb:75:in `block (3 levels) in <top (required)>'
The application in development mode still runs fine.
Both Rspec 2.11.0 and Rails 3.2.6 uses the latest Journey gem (1.0.4). It has some problems, and by explictly lock it to the previous version the spec error disappears.
gem 'journey', '1.0.3'
UPDATE
I recently updated Rails to 3.2.11 with Journey 1.0.4, and all spec passed. My Rspec is 2.11.0
Therefore there is no need to downlock journey anymore, just update Rails.
It appears that the environment is stricter in functional tests than it is in production or development.
In the latter two, it is unable to "know" the parameter names beforehand as they are determined by looking at the according/matching route definition.
In a test, however, one provides the parameter name explicitly. This allows the environment to be more picky.
As that behaviour drifts away from the principle of having a test-env match a prod-env as closely as possible, I consider it a bug and filed an issue accordingly (https://github.com/rails/journey/issues/59).
In order to work around the problem for now, make sure your parameter names match your routes exactly.
I suggest adding the according routes until an outcome is decided in regards to the filed issue. That way, if it's consired a bug and resolved, you just need to remove the routes again - instead of fiddling with your production logic on controller level (which is working flawlessly already).

as_paperclip_bridge initialization error in rails3

I'm trying to use both of PaperClip and ActiveScaffold with help of as_paperclip_bridge in a rails3.0.5 project.
However, following initialization error is occurred when I launch the project.
=> Booting WEBrick
=> Rails 3.0.5 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
C:/Users/ken/Documents/NetBeansProjects/fcheck/vendor/plugins/as_paperclip_bridge/init.rb:10: undefined method bridge' for ActiveScaffold:Module (NoMethodError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/plugin.rb:81
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:ininstance_exec'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:25:in run'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:50:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:in each'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/initializable.rb:49:inrun_initializers'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:134:in initialize!'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:insend'
from C:/Ruby187/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/application.rb:77:in method_missing'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config/environment.rb:7
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:inrequire'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in new_constants_in'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from C:/Ruby187/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:3
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:ininstance_eval'
from C:/Ruby187/lib/ruby/gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in initialize'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1:innew'
from C:/Users/ken/Documents/NetBeansProjects/fcheck/config.ru:1
The code in as_paperclip_bridge\init.rb is attempting to call a module method 'ActiveScaffold.bridge' but it coun't be found.
Even though, same code is working without error in rails2.3.8 project.
We can see a big difference of rails initialization code between version 2 and 3.
On rails 2.3.8, plugins are loaded in 'load_plugins' method which is called after 'load_gems' method in initializer.rb. However, rails3 doesn't have initializer.rb and the loading process seems to be totally different.
I also have tried to remove AS gem and install both of AS plugin with as_paperclip_bridge plugin. But, the error haven't disappeared.
Could someone explain why the error is occurring?!
Anyway, I really hope to get any solution or workaround.
Thanks,
Kenichi
Self reply.
I had realized that as_paperclip_bridge was not required for latest ActiveScaffold implementation. (It's including the bridge)
Please make sure to install ImageMagick and RMagick gem to use PaperClip for image files. Or, you may also think 'as_paperclip_bridge should be there'
Thank you,
Kenichi

undefined method `cache_sweeper' for ActionController::Base:Class - warbler

I am deploying my Jruby Rails application on glassfish with acts_as_audited as a gem/plugin installed.
Whenever I try to Audit my model, I am going to get the following error.
My Environment is: Jruby 1.6.0.RC2, Rails 3.0.3
You can refer here if you guys want to look more on the error http://www.ruby-forum.com/topic/1053934
Please help me out, I stuck up here
Application Error
org.jruby.rack.RackInitializationException: undefined method `cache_sweeper' for ActionController::Base:Class
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:44:in `class_eval'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:44
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/acts_as_audited-2.0.0.rc6/lib/acts_as_audited.rb:68:in `require'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:68:in `require'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `each'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:66:in `require'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `each'
from /home/dev2/glassfishv3/glassfish/domains/domain1/applications/gavel/WEB-INF/gems/gems/bundler-1.0.10/lib/bundler/runtime.rb:55:in `require'
... 20 levels...
I reported this problema as a bug in jruby-rack.
A workaround is to add require 'active_record' if defined? $servlet_context after require 'rubygems' in config/boot.rb or manually including sweeping somwhere in application.rb ActionController::Base.send(:include, ActionController::Caching::Sweeping) if defined? $servlet_context.
I think I recognise this problem. It looks like acts_as_audited uses cache sweepers. I've had this problem with cache sweepers.
You need to explicitly include the caching module in your ApplicationController:
class ApplicationController < ActionController::Base
# JRuby not finding cache sweeper at runtime in production
include ActionController::Caching::Sweeping if defined?(JRUBY_VERSION)
# Rest of your class here...
end
I'm not sure why this happens, but it's probably a loading/resolution issue related to running in threadsafe mode for production.