Newly installed will_paginate 3.0.0
gem 'will_paginate', '~> 3.0.0', :require=>'will_paginate/data_mapper'
Running a controller query:
#tickets = Ticket.paginate(:page => params[:page], :per_page => 5,:username => #ticket.username)
Which works, pulls up all the tickets for a user and paginates in 5's if I put ?page=X where x is a page number in the url.
=will_paginate(#tickets)
in the view does not work, this results in
undefined method `will_paginate' for #<#<Class:0x000000053674c8>:0x0000000535cd48>
So will_paginate works, but not the view helper. Am I missing something? I'm using slim templating if that makes any difference. Is there some syntax change I'm missing? The documentation is simple but unhelpful beyond this point. I looked into the source, and there does not seem to be any changes, but I cannot figure why it is inaccessible
And then on tangent, this messes with an association.
=> #instance.model_belonging_to_instance.create(:text=>'test')
TypeError: can't convert nil into Integer
from /home/qx/.rvm/gems/ruby-1.9.2-p180/gems/will_paginate-3.0.0/lib/will_paginate/page_number.rb:16:in `Integer'
etc etc et al
SOLUTION:
gemfile:
gem 'will_paginate', '~> 3.0.0' # removed this, :require=>'will_paginate/data_mapper'
intializer:
require 'will_paginate'
require 'will_paginate/data_mapper'
It shows up, but if not at the top of the template, I get a
stack level too deep
error I am unable to interpret
Don't use the :require option in the Gemfile, as you already figured out; instead require "will_paginate/data_mapper" somewhere in config/application.rb, for instance after the Bundler setup.
There is a similar question with an answer that indicates that auto-requiring here is the problem. See will_paginate undefined method. The Will_paginate gem appears to work though for the question and answer.
gem 'will_paginate', '~> 3.0.0', require: %w[
will_paginate
will_paginate/data_mapper
]
Related
I was using will_paginate for pagination on my site but as we're using Active Admin I decided to change it to kaminari to avoid any of the conflict issues between the two. I removed will_paginate from the gem file and added kaminari, restarted the rails server and ran bundle install but I'm getting errors which suggest it has not been installed properly:
undefined local variable or method `page' for <SearchController:0x007fd546587140>
Rails version: 5
Gemfile:
gem 'kaminari', '~> 0.16.3'
#gem 'will_paginate', '~>3.1.6'
Controller:
...
#properties = #properties.page(page[:params]).per(9)
Not sure what the issue is?
There is no object page in your controller...
#properties = #properties.page(page[:params]).per(9)
I think what you wanted to do was...
#properties = #properties.page(params[:page]).per(9)
I'm running into this error after installing rails 5.0.0 on my project. I'm starting to think it's Devise gem or something. I tried multiple ways, but can't seem to figure it out.
I've tried this for devise gem, but same result.
gem 'devise', :github => 'plataformatec/devise', :branch => 'master'
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <top (required)> at /home/nitrous/code/uvesty/config/environment.rb:5)
Exiting
/home/nitrous/code/uvesty/.bundle/gems/actionpack-5.0.0/lib/action_dispatch/middleware/stack.rb:108:in `assert_index': No such middleware to insert after: ActionDispatch::ParamsParser (RuntimeError
I also thought I might need to change all my
#user = User.find(params[:id])
to
#user = User.find_by(id: params[:id])
First change devise declaration in Gemfile like
gem "devise", '~> 4.0.0.rc1'
Secondly, you don't need to change this line, as find method is NOT deprecated.
#user = User.find(params[:id])
Please check what new in rails 5
The issue was the gem rails_admin. I removed it and it's all fine now. It seems they might have not updated their gem for rails 5.0.
I would like to convert some numbers in words.
So I installed the numbers_and_words gem with "gem install numbers_and_words" -
I restarted the server, and tried to run this example from the Read.me in my index.html.erb:
<%= 42.to_words %>
but I get this error:
NoMethodError in Posts#index -
undefined method `to_words' for 42:Fixnum
I checked the gem documentation a few times, but I couldn't figure out, what I am missing.
This is my posts controller regarding index.
def index
#posts = Post.order("created_at desc")
#published = Post.where(draft:false).order("created_at desc")
#drafts = Post.where(draft:true).order("created_at desc")
respond_to do |format|
format.html # index.html.erb
format.json { render json: #posts }
end
end
What did I wrong? Did I forget something in the installation process?
I am quite new to rails, sorry if this is a trivial newbie question.
Thank you so much for your help! Really appreciated.
Installing a gem is not sufficient to make it available in a Rails project. You need to add it to the Gemfile so that you can manage the dependencies with Bundler.
Edit the 'Gemfile' and add the gem
gem 'numbers_and_words'
Then run bundle again to update the Gemfile.lock
$ bundler
This will make the gem available to the app. It will also autorequire the gem on boot, if the gem uses the standard naming conventions.
It seems this gem is name correctly. Otherwise, you can explicitly require it by setting a require option in the gemfile
gem 'numbers_and_words', require: 'numbers_and_words'
If you just installed the gem locally and you didn't configure the Gemfile, the application will crash once you will deploy it.
Found a solution - not mentioned in the documentation of the gem, but it did the trick for me:
I added
require 'numbers_and_words'
in the rake file. After server restart, it's working.
I am interested in any solution the title describes.
My gemfile is:
gem "rails", "~> 4.0.0"
gem "mongoid", "~> 3.1.3"
gem 'rails-observers'
I want to use observers on my mongoid models but I receive this error:
https://github.com/mongoid/mongoid/issues/3108
Any ideas are welcome
I just implemented this gem, https://github.com/chamnap/mongoid-observers/, because I often need it. Please have a look and give me feedback.
It looks like you need to include the module in each model and set the observers.
class ORM
include ActiveModel::Observing
end
# Calls PersonObserver.instance
ORM.observers = :person_observer
# Calls Cacher.instance and GarbageCollector.instance
ORM.observers = :cacher, :garbage_collector
# Same as above, just using explicit class references
ORM.observers = Cacher, GarbageCollector
https://github.com/rails/rails-observers/blob/master/lib/rails/observers/active_model/observing.rb#L19
I'm using the google-api-client gem (gem google-api-client, '0.4.1' in my Gemfile). The following code caused the error uninitialized constant MyController::Google:
class MyController < ApplicationController
def index
#client = Google::APIClient.new
end
end
Specifying ::Google::APIClient didn't help, the error then said uninitialized constant Google.
Simply adding a require 'google/api_client' at the top of the file made this go away, so it seems there's something wrong in how auto-loading is being done. Not sure what's going on here exactly, specifying the gem in my Gemfile should have automatically required the gem, right? I have restarted the rails server btw.
Try adding a :require => 'google/api_client' where you specify the google api client gem in the Gemfile
gem 'google-api-client', :require => 'google/api_client'
This tells bundler that the correct way to require the gem 'google-api-client' is to require 'google/api_client'