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.
Related
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.
I want to have https for entire application.
I decided to use this gem:
https://github.com/tobmatth/rack-ssl-enforcer
However after adding at end
gem 'rack-ssl-enforcer'
in Gemfile and
config.middleware.use Rack::SslEnforcer
in application.rb at end I get error:
/path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send': undefined method `Rack' for #<App1::Application:0xf6dcb314> (NoMethodError)
from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /path_to_app/www/stolikarnia/config/application.rb:57
from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:21:in `require'
from /path_to_app/www/.ruby/gems/1.8/gems/railties-3.0.9/lib/rails/commands.rb:21
from script/rails:6:in `require'
from script/rails:6
As you see from logs i use Rails 3.0.9. I can't upgrade to RoR 3.1.0 because of dependencies.
In your Gemfile change the requirement to
gem 'rack-ssl-enforcer', :require => 'rack/ssl-enforcer'
Then, in your application.rb pass the class name as String to take advantage of lazy evaluation.
config.middleware.use "Rack::SslEnforcer"
As a side note, I encourage you to check https://github.com/josh/rack-ssl. It's the middleware introduced in Rails 3.1. You can already use it in Rails 3.0 with the additional benefit you won't need to change it once you'll upgrade to Rails 3.1.
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
I've been trying to play around with the Kaminari gem for pagination, but am running into problems.
I've got a simple starter project with a simple model:
class Position < ActiveRecord::Base
validates_presence_of :name
end
I'm running with ruby 1.9.2 and rails 3.0.5 on Ubuntu 10.04. I've installed kaminari (0.10.4).
From what I understand, I should be able to execute Position.order("name").page(1), but when I do so, I get the following:
ruby-1.9.2-p0 > Position.order("name").page(1)
NoMethodError: undefined method `page' for #<ActiveRecord::Relation:0xaacab34>
from /home/bob/.rvm/gems/ruby-1.9.2-p0#talentskout/gems/activerecord-3.0.5/lib/active_record/relation.rb:371:in `method_missing'
from (irb):2
from /home/bob/.rvm/gems/ruby-1.9.2-p0#talentskout/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'
from /home/bob/.rvm/gems/ruby-1.9.2-p0#talentskout/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'
from /home/bob/.rvm/gems/ruby-1.9.2-p0#talentskout/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This seems about as simple a scenario as I can get. Any ideas would be greatly appreciated.
Thanks.
Rails noob here: had precisely the same issue but for a different reason - I found I had to restart the server after adding the kaminari gem and running bundle install. Just mentioning it in case someone else has the same problem!
I figured out my problem, and it have nothing to do with the Kaminari gem per se.
In my Gemfile, I had put the gem 'kaminari' clause under my group :test section by mistake. So it wasn't loading in my development environment. Silly mistake.
I'm also a Rails noob and had the same error. I could solve the problem by changing Model.all to Model.order("id").
I updated my system to opensuse 11.4 and set up Ruby 1.9.2 via RVM. I reinstalled all the gems and updated bundle all without issue.
The problem is the vague error I get when running the app:
ActionController::RoutingError (undefined method `sub' for nil:NilClass):
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/news_controller.rb:1:in `<top (required)>'
I don't even know where to start looking for the problem. Both files on line 1 is the class declaration. ie class NewsController < ApplicationController and class ApplicationController < ActionController::Base. Neither files have a method call to 'sub' and no other information is given.
The app worked perfectly before the upgrade (which was using Rails 3.0.5 also) so I think the issue is somewhere in Rails, except running a new application with a simple scaffold has no problems. news#index is root in the routes file, but changing root to something else does nothing.
EDIT:
resources :categories,:addresses,:calendars,:topics,:profile,:news,:account_setting
resources :boards do
member do
get :move
post :move_category
end
end
get "user/index"
get 'login/index'
get 'login/new'
post 'login/create'
post 'login/authenticate'
get 'login/forgot_password'
put 'login/reset_password'
root :to => "news#index"
No need to do all that. I think the solution was probably a lot simpler. I just got the same error. Turns out I just had a misnamed helper module:
module AssetHelper
...
end
Should've been
module AssetsHelper
...
end
I got it resolved, although I don't know what caused it.
I created a new app and copied over app, routes, db, lib, and public and the problem disappeared.