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.
Related
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.
I have added the emdedly-ruby gem (https://github.com/embedly/embedly-ruby) to my social bookmarking appliction. Embedly pulls in an image from a url and replaces the url link with the image in my application. It is working perfectly in local, but it doesn't work in production (Heroku). I am new to programming and I do not know how to capture an error in production. Any suggestions would be much appreciated!
Here is my bookmark.rb model file:
class Bookmark < ActiveRecord::Base
#attr_accessible :thumbnail_url
has_many :bookmark_topics
has_many :topics, through: :bookmark_topics
has_many :user_bookmarks
has_many :users, through: :user_bookmarks
has_many :likes, dependent: :destroy
default_scope { order('updated_at DESC') }
after_create :set_embedly_url
private
def set_embedly_url
embedly_api = Embedly::API.new :key => ENV['EMBEDLY_API_KEY'],
:user_agent => 'Mozilla/5.0 (compatible; mytestapp/1.0; my#email.com)'
Rails.logger.info ">>>> embedluy object: #{embedly_api.inspect}"
obj = embedly_api.extract :url => self.url
Rails.logger.info ">>>> embedly obj: #{obj.inspect}"
# get result and find the attribute for the thumbnail_url
# set the bookmark's thumbnail_url with that value -- update_attribute(thumbnail_url: val_of_thumbnail_url_from_response)
o = obj.first
Rails.logger.info ">>>> o: #{o.inspect}"
image = o.images.first
Rails.logger.info ">>>>> image: #{image.inspect}"
update_attribute(:thumbnail_url, image['url'])
Rails.logger.info ">>>> Now i am: #{self.inspect}"
true
end
end
Here is my bookmark.html.erb partial file in views:
<div class="btn-group">
<% show_remove_button ||= false %>
<li>
<div class="bookmark_container">
<div class="thumbnail">
<% link_text = bookmark.thumbnail_url.present? ? "<img src='#{bookmark.thumbnail_url}'/>".html_safe : bookmark.url %>
<%= link_to link_text, bookmark.url %>
</div>
</div>
<% if current_user %>
<div class="like">
<% if show_remove_button %>
<% user_bookmark = get_user_bookmark_for(bookmark) %>
<% if user_bookmark %>
<%= link_to "Remove", user_bookmark_path(user_bookmark), class: 'btn btn-danger', method: :delete %>
<% end %>
<% else %>
<% if like = current_user.liked(bookmark) %>
<%= link_to [bookmark, like], class: 'btn btn-info', method: :delete do %> Unlike <% end %>
<% else %>
<%= link_to [bookmark, Like.new], class: 'btn btn-info', method: :post do %> Like <% end %>
<% end %>
<% end %>
</div>
<% end %>
</li>
and here is my application.js file in my javascript folder:
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
Here is my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.5'
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development do
gem 'sqlite3'
end
gem 'bootstrap-sass', '~> 3.1.1'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem 'devise'
gem 'faker'
gem 'figaro'
gem 'embedly'
Please let me know if there are any other files you would like to see. I have also read through embedly tutorials at http://embed.ly/docs/api/tutorials, but I am not using jquery in my code to make embedly work, as they are using in the tutorials. Do you think I am required to use jquery in my code to make it work? But then why would embedly work in local without jquery and not in production?
After a cursory look at your code, I can't tell for sure why it isn't working in Production, if it's working on local, but here are some debugging thoughts.
Firstly, try to be specific (in your own debugging and with SO), about what "not working" means. Is it throwing an error (where/when/how)? Is it printing a link with no embedded behavior? Is it printing the full Embedly link as an HTML string? Etc. This will help you/us narrow this down.
Once you have a sense for what is going wrong more precisely, here are some next steps for debugging:
If it's throwing an error, that's likely because a), you haven't included Embedly environment variables on Production that are necessary and included locally (such as the EMBEDLY_API_KEY), or some similar tool setup issue, or b), you haven't migrated the thumbnail_url column on Heroku, or something that causes a database issue.
In either case, you can probably best diagnose this issue by producing the error on production and then running heroku logs from your console to get a view of the most recent production server logs. You could also do heroku logs --tail to get a running log. These would help you see any errors, and also see, because of your puts statements, what is and isn't successfully run.
If it's not throwing an error, and not showing up, this might be a JS error.
To diagnose this, open up the JavaScript console in Web Inspector (CMD+Shift+J on a Mac, I believe) to see if there are any JS errors, either in loading files (your Embedly library, etc) or in your JS files themselves. This might have to do with how Heroku deals with the Asset Pipeline. If this is the case, check out the Rails Guide to the Asset Pipeline for some heavy/interesting reading.
The least likely of the cases that comes to mind is that it's just not HTML sanitizing or something, in which case you'd just see a blob of HTML on the page. In that case, I'd just Google the HTML sanitization method you're using and "production" or something, to see what else people have run into, or edit the question or start a new one, with the narrower error description.
Hope that helps!
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.
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
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>