Having problems with my will_paginate after upgrading to Rails 3 - ruby-on-rails-3

The problem is that I keep getting
NoMethodError (undefined method `paginate' for #<Class:0x1e3dec0>):
activerecord (3.0.3) lib/active_record/base.rb:1008:in `method_missing'
Below is the code snippet I am including and any help in fixing my problem. I am using will_paginate-rails3 at the moment.
def list
#users = User.paginate :per_page => 10, :page => 1
end
in user_controller.rb
and also
<!-<%= link_to 'Previous page', { :page => #users.previous_page } if #users.previous_page %>-->
in my views.html.
Could someone please point me in the right direction?

Did you use the Rails 3 branch of will_paginate? It's here:
https://github.com/mislav/will_paginate/tree/rails3
Specify it in your Gemfile like this:
gem 'will_paginate', '~> 3.0.beta'
then install it like this:
bundle install

Related

will_paginate - list alphanumerically?

Can anyone recommend how to use the will_paginate gem to paginate a list alphanumerically?
There is this plugin:
http://sermoa.wordpress.com/2010/08/25/rails-alphabetical-pagination/
But I was hoping to get my hands on a method with will_paginate
Thanks!
Adam
I just add this in my model:
default_scope order: 'users.name ASC'
Although you could alternatively just do this in your controller:
#users = User.page(params[:page]).order(:name)
Works with kaminari and, I assume, will_paginate

Rails 3: PDF generation with wicked_pdf suddenly does not work anymore ? [undefined method `virtual_path']

Our platform has been online for a while and working just fine. Our customers are able to download their invoices in PDF format just fine.
We've been working on a upgrades for a few month, and just today we noticed that "suddenly" non of our PDF generation with wicked_pdf and wkhtmltopdf no longer worked...
I have absolutely no idea why, I checked everything I could think of:
- routes
- initializers
- gems
- etc.
Everything seems to be fine, same as the actual only version.
We have not changed Rails or Ruby version. Everything is pretty much the same:
- Ruby 1.8.7 REE
- Rails 3.0.10
The error we are getting is:
Rendered groups/clients/proforma.pdf.haml (103.4ms)
Sent data toto.pdf (2.7ms)
Completed 500 Internal Server Error in 6892ms
NoMethodError (undefined method `virtual_path' for text template:ActionView::Template::Text):
app/controllers/groups/clients_controller.rb:980:in `proforma'
app/controllers/groups/clients_controller.rb:976:in `proforma'
lib/include/flash_session_cookie_middleware.rb:16:in `call'
lib/include/flash_session_cookie_middleware.rb:16:in `call'
The controller looks like:
def proforma
#request = WireRequest.where(:_id => params[:id], :status => :pending).first
respond_to do |format|
format.html {render :layout => false}
format.pdf do
unless #request.nil?"
render(:pdf => "PROFORMA_#{#request.invoice_num}", :layout => 'pdf')
end
end
end
end
Any ideas of what could be going wrong? I have no more ideas :(
I already had this kind of issue using the new relic rpm for developers.
I forked the gem here.

Redcarpet 2.0.1

I'm following this tutorial but it keeps failing saying "undefined method `new' for Redcarpet:Module". I have gem "redcarpet" in my Gemfile. The piece of code that is failing:
Redcarpet.new(#post.content).to_html
Okay, it looks like Redcarpet 2 has completely changed the API. The following works:
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
:autolink => true, :space_after_headers => true)
raw markdown.render(#post_content.content)

Paper_trail and Kaminari problem

I have a ActiveRecord model from paper_trail gem called 'Version'.
I want to create resource with displaying version records.
But Kaminari doesn't add 'page' scope to Version.
Any model has 'page' methods but Version doesn't
Example:
Version.methods.grep /page/
=> []
MyAnyModel.methods.grep /page/
=> [:page, :default_per_page]
this is a bug of kaminari gem -
details are here : https://github.com/amatsuda/kaminari/pull/119
try to use
gem 'kaminari', :git=>"https://github.com/Casecommons/kaminari.git"
try to use this
Kaminari.paginate_array(my_array_object).page(params[:page])
resource:
https://github.com/amatsuda/kaminari

How to stop will_paginate from getting every post from the database

I am just playing around with Ruby on Rails 3.0 with a simple message board and found several issues with will_paginate.
The most pressing is that each time a new page is displayed a database query of every single post in the topic is performed.
As you can imagine, if you have a topic with 10,000+ posts this is very slow.
Is there a way to stop this odd behavior?
Show controller:
#posts=#topic.posts
#posts = Post.paginate #posts, :page => params[:page],:order => "post_number"
Model
cattr_reader :per_page
##per_page = 20
view
<%= will_paginate #posts %>
In your controller try:
#posts = Post.paginate_by_topic_id #topic.id, :page => params[:page],:order => "post_number"
Look at the example in the will_paginate docs
Upgrade will_paginate to version 3.0.0. Then:
class Post
self.per_page = 20
end
#topic.posts.page(params[:page]).order("post_number")