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").
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 am trying to do a bundle install, but I'm getting the following error:
Unfortunately, a fatal error has occurred. Please see the Bundler troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/home/nish/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/util.rb:40:in `inflate': buffer error (Zlib::BufError)
from /home/nish/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/util.rb:40:in `inflate'
from /home/nish/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems.rb:536:in `inflate'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/fetcher.rb:93:in `fetch_spec'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/remote_specification.rb:46:in `_remote_specification'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/remote_specification.rb:51:in `method_missing'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:95:in `block (2 levels) in unmet_dependency_names'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:94:in `map'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:94:in `block in unmet_dependency_names'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:93:in `map'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:93:in `unmet_dependency_names'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:240:in `remote_specs'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:163:in `fetch_specs'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/source/rubygems.rb:67:in `specs'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:192:in `block (2 levels) in index'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `each'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:189:in `block in index'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/index.rb:9:in `build'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:185:in `index'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:179:in `resolve'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:114:in `specs'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/definition.rb:109:in `resolve_remotely!'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/installer.rb:83:in `run'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/installer.rb:14:in `install'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/cli.rb:247:in `install'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/bin/bundle:20:in `block in <top (required)>'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/gems/bundler-1.3.5/bin/bundle:20:in `<top (required)>'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/bin/bundle:23:in `load'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#global/bin/bundle:23:in `<main>'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#voylla/bin/ruby_noexec_wrapper:14:in `eval'
from /home/nish/.rvm/gems/ruby-1.9.2-p320#voylla/bin/ruby_noexec_wrapper:14:in `<main>'
I tried the following:
gem update --sysytem
But still I'm getting the same error. Please can someone help!. Thanks
SOLUTION
Found out what is causing the problem. In the case we are are using geminabox and the for what ever reason the railties-4.1.6.gemspec.rz was corrupted. Don't know how it happened but it was. So what we did was removed the railties-4.1.6
rm shared/gems/proxy/quick/Marshal.4.8/railties-4.1.6.gemspec.rz
after that the system bundled like normal. If you are having the same problem you are going to have to find a way to watch the network calls and see which one of the GET events it is stopping on.
EXTRA READING does not fix bug only suppresses it in some cases
The reason this worked was because the new version used a different version of railties by happen chance. It only gave the impression that this fixed the problem.
Here is some extra info on this bug. But it doesn't total explain why this is happening.
cannot install ruby gems - zlib error
Now they have removed or fixed this code in the v2.0.0-p451 but the ruby-2.1.0 has yet to merge the patches I have yet to go back threw all the code and check each and every version but here is how you can check.
What you are looking for is this file. lib/rubygems/util.rb in there is a method called inflate this method is responsible for unzipping the gem file. However there is some sort of bug with it where it is being called on things that can't be unzipped.
This is a stable version and you wont find lib/rubygems/util.rb v2.0.0-p481. So this is difficult to find but by looking at the source code you can figure out which ones have this bug and which ones don't.
If you are using rvm use this commands to install the correct version
rvm install ruby-2.0.0-p481
To see all know ruby version avaliable you can run this command below.
$ rvm list known
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p547]
[ruby-]2.0.0-p451
[ruby-]2.0.0[-p481]
[ruby-]2.1.1
[ruby-]2.1[.2]
[ruby-]2.1-head
ruby-head
...
By changing to that patch version you will should be ok. I have also found this bug using ruby-2.0.0-p247 as well.
The above code would suggest that you have the bug as well. However it is strange because the github repo says that it was not introduced until Nov 18, 2013.
https://github.com/ruby/ruby/commit/a7fa4d5d9aab150ad4b0c3f3217fe444df69f527.
Anyway I know there is a lot of information here but this bug is tricky. It seams to only effect some version of ruby but because of organization of the code it is hard to tell some times if it is in your version. Best way is to just check to see if you have the util.rb file and if you do then change versions.
Using the the comma gem and exporting CSV files perfectly fine on my local environment. Also working on our staging environment which is running on an AWS instance.
ONLY failing on Heroku.
Heroku says:
2013-08-21T21:55:34.875724+00:00 app[web.1]: NoMethodError (undefined method `klass' for nil:NilClass):
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/models/job.rb:220:in `block in <class:Job>'
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/controllers/jobs_controller.rb:25:in `block (2 levels) in index'
2013-08-21T21:55:34.875724+00:00 app[web.1]: app/controllers/jobs_controller.rb:18:in `index'
And line 220 in my Job model is:
Comma do
...
customer :first_name
...
end
job.rb includes the line:
belongs_to :customer
And customer.rb has:
has_many :jobs
And as I mentioned this entire thing works great on my local box - I click the export button and out pops all the jobs, with each customer in the appropriate column.
For whatever reason it's only failing on Heroku.
I'm using Ruby 2.0.0-p0 on Heroku, Comma gem only verified up to 1.9.2 according to the documentation - BUT - I'm using Ruby 2.0.0-p0 on the staging server AND on my local environment and, again, it's working.
It's the 'klass" that's really throwing me off, because I don't have that anywhere in my code. I've read other threads about the same error and their solutions, but I don't have things like nested model forms and the like.
It is some issue with Heroku & Ruby 2.0 and associations? I've got the has_many and belongs_to on both sides, but still seems to be misunderstanding the association...
UPDATE
From the framework trace:
comma (3.1.0) lib/comma/extractors.rb:72:in `get_association_class' <====
comma (3.1.0) lib/comma/extractors.rb:55:in `block in method_missing'
comma (3.1.0) lib/comma/extractors.rb:48:in `each'
comma (3.1.0) lib/comma/extractors.rb:48:in `method_missing'
comma (3.1.0) lib/comma/extractors.rb:15:in `instance_eval'
comma (3.1.0) lib/comma/extractors.rb:15:in `results'
Your code may be the same on both local and prod, and it looks like you're using the same Rails/Ruby versions on local and production (good stuff!), but maybe your data isn't. Perhaps what's wrong is that in production you're retrieving a Job and navigating to some association, but that association doesn't exist, you're getting a nil, and kaboom?
It turned out that this was a legitimate bug in Comma gem - https://github.com/comma-csv/comma/releases
I reported and they accepted, fixed, and released v 3.1.1
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 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.