How to Install Kaminari Properly? - ruby-on-rails

I'm having a bit problem on how to get Kaminari work. I did the installation procedure in GitHub.
gem "kaminari"
Then run
bundle
I have this snippet for index
#users = User.order("name")
I added this on my view
<%= paginate #users %>
Then I got this error.
undefined method `paginate' for #<#<Class:0x00000102934330>:0x00000102932508>
Did I missed something? I also tried to include the page method
#users = User.order("id").page(1)
But I get this error instead
undefined method `page' for #<ActiveRecord::Relation:0x000001017d0300>

include kaminari and bootstrap-kaminari-views gems in your project Gemfile,
gem "kaminari"
gem "bootstrap-kaminari-views"
Execute bundle install in terminal,
$ bundle install
In products_controller.rb,
#products = Product.order("name")
#products = Kaminari.paginate_array(#products).page(params[:page]).per(5)
In products/index.html.erb,<%= paginate #products, :theme => 'twitter-bootstrap-3' %>

take a look at the railscast for kaminari
its really nice
http://railscasts.com/episodes/254-pagination-with-kaminari
bash
rails g kaminari:views default
products_controller.rb
#products = Product.order("name").page(params[:page]).per(5)
products/index.html.erb
<%= paginate #products %>
app/views/kaminari/_prev_span.html.erb
<span class="prev disabled"><%= raw(t 'views.pagination.previous') %></span>

Related

unable to implement kaminari gem

I have error implementing kaminari gem for pagination
I have the same issue here. I am using Rails 7
I have alread add gem 'kaminari', '~> 1.2', '>= 1.2.2' to my Genfile and run bundle install
blogs_controller.rb
def index
#blogs = Blog.page(params[:page]).per(5)
end
View
<div class="col-md-8 blog-main">
<%= render #blogs %>
<%= paginate #blogs %>
</div>
Error
ActionController::UnfilteredParameters in Blogs#index
Showing /home/emmy/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/kaminari-0.16.3/app/views/kaminari/_paginator.html.erb where line #14 raised:
unable to convert unpermitted parameters to hash
I will appreciate any help. Thank you.

Will_paginate gem is not installing - Rails 4

for something reason will_paginate is not installed.
i have put the line
gem 'will_paginate', '~>3.0.6'
in my gemfile,
i even ran "gem install will_paginate" in the console.
it says installed sucessfully but using the instructions to check if will_paginate is indeed install returns false nil
reference:
>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate
If any of these lines return nil/false, will_paginate has not properly loaded in your app.
and i get this error when implemented
undefined method `total_pages' for #<Post::ActiveRecord_Relation:0x007fa40773bc18>
UPDATE:
I specifically stated in my gemfile to install version 3.0.5 not the latest version(3.0.7) and the gem is loaded properly. BUT the error with the total_pages still remains.
more info:
controller:
#posts = Post.paginate(:page => params[:page])
view:
<%= will_paginate #posts %>
UPDATE 2:
FIXED the error (had a typo) BUT i cannot see visually the gem anywhere on the page.

rails 2.3 will_paginate 2.3.16 undefined method `paginate' for #<Class:0x7f0ed5f13138>

I've found a lot of links regarding this problem googling. but nevertheless I still get this error after implementing those fixes.
so my gemfile
gem 'will_paginate', '~> 2.3.16'
environment file
config.gem 'will_paginate', :version => '~> 2.3.16'
Controller
def index
#events = Event.paginate({:page => params[:page], :per_page => 10})
end
View:
<% #events.each do |item| %>
...
<% end %>
...
<%= will_paginate #events %>
I'm using rvm, console commands
rvm 1.8.7 do bundle install
...
rvm use 1.8.7 do bundle exec rake gems:install
Could anyone help me with this problem?
try this one
def index
#events = Event.all.paginate({:page => params[:page], :per_page => 10})
end
Note: If u get same error still, then just comment out logic of pagination and insert some records in your database table(model) and then use pagination.
You cannot call paginate on a model. It can be called on collections like hashes, array, ActiveRecord.
It may be just a case of restarting the server after you have installed the gem.

Why will_paginate not loaded in rails 3.2.8 engine?

Here is the code in our index to return #customers:
#customers = Customerx::Customer.where(:active => true).order("since_date DESC, id DESC").paginate(:per_page => 30, :page => params[:page])
It causes error of below:
undefined method `paginate' for #<ActiveRecord::Relation:0x6b88960>
In debug, ActiveRecord::Base.respond_to? :paginate returns false. It seems to us that the will_paginate was not loaded, even though will_paginate (3.0.3) was returned with gem list.
What could be wrong with the code?
The problem was fixed by adding gem will_paginate in engine's gemfile, even though gem will_paginate is in gemspec for the rails engine. The problem was caused by gem paginate was not loaded as ActiveRecord::Base.respond_to? :paginate returned false.
Here is a post that is somewhat similar to the problem here.
Rails Engine - Gems dependencies, how to load them into the application?
even I used to get this error, so I tried page method...use
#customers = Customerx::Customer.where(:active => true).order("since_date DESC, id DESC").page(params[:page]).per_page(30)

Feedzirra Not Installed Properly?

I'm trying to use Feedzirra in my Rails 3.2 app to do simple feed parsing. I found this online: http://asciicasts.com/episodes/168-feed-parsing. I followed the instructions there to install the gem, but I believe this instructions are somewhat out of date, since it refers to placing a config.gem line in my config/environment.rb file, which cannot accommodate such calls. I am getting an uninitialized constant ApplicationController::Feedzirra error and I'm not sure why.
I put this code in my application controller:
before_filter :load_blog_feed
def load_blog_feed
feed = Feedzirra::Feed.fetch_and_parse(feed_url)
#blog_posts = feed.entries[0...3]
end
I placed this line in config/application.rb:
config.gem "pauldix-feedzirra", :lib => "feedzirra", :source => "http://gems.github.com"
Lastly, I placed this code in a view:
<div id="blog_feed">
<% #blog_posts.each do |post| %>
<p>
<span class="post_title"><%= link_to "#{post.title} >>", post.url %></span><br>
by <span class="post_author"><%= post.author %></span> on <span class="post_date"><%= post.published %></span>
</p>
<% end %>
</div>
For Rails 3.2 , to be more precise, add the following line to config/application.rb file :
config.gem "feedzirra", :lib => "feedzirra", :source => "http://gems.github.com"
and following line to Gemfile :
gem 'feedzirra'
Then run :
bundle install
Then you can use feedzirra in your application smoothly.
Ok, I found the answer... just include gem 'feedzirra' in your Gemfile and run bundle install. gem 'pauldix-feedzirra' doesn't seem to work, though.
use Bundler!
place
----- EDITED
gem 'feedzirra'
into Gemfile, and run bundle install

Resources