Rails - will_paginate says variable appears to be empty. Did you forget to pass the collection object for will_paginate?
You can do something like this in your controller:
@car_paginator = Car.paginate(page: params[:page], per_page: 5).order(created_at: :desc)
@cars = @car_paginator.group_by { |r| r.created_at.to_date }
Then change the line with the pagination in your view:
= will_paginate @car_paginator
The problem is: When you use the paginate
method the results is not a normal array or database relation but an object that has some extra information like @size
. If you run group_by
on that you remove that extra attributes and return a plain hash.
Did you forget to pass the collection object for will_paginate? Rails
<%= will_paginate @conversations %>
Check this you need to pass the variable, you want to paginate.
The users variable appears to be empty for will_paginate
Replace
@questions = Question.order("question").page(params[:users]).per_page(2)
With
@questions = Question.order("question").paginate(:page => params[:page], :per_page => 2)
EDIT
Update the User model as below:
class User < ActiveRecord::Base
has_many :sender_questions, :class_name => 'Question', :foreign_key => 'sender_id'
has_many :recipient_questions, :class_name => 'Question', :foreign_key => 'recipient_id'
end
Update the UsersController#show action as below:
def show
@user = User.find(params[:id])
@question = @user. recipient_questions.paginate(page: params[:page])
end
@users variable empty. forget to pass the collection object for will_paginate?
In your Users controller, make sure you have @users and if you are using will_paginate, make sure you call .paginate(page: params[:page], per_page: 20]
and in your view, have <%= will_paginate @users %>
.
will_paginate -ActionView::Template::Error variable appears to be empty
As official will_paginate gem documentation says: you should pass your collection (@loadVerifications
in your case) as a parameter to will_paginate
view helper:
<%= will_paginate @loadVerifications %>
Here's the source code which raises this error.
method call from within will_paginate
method.
method declaration.
Briefly: if no collection is given to will_paginate
helper, it tries to build instance variable's name from controller's name
How can i add will_paginate method to where condition in rails
#will_paginate
expects a collection as argument.
<%= will_paginate @products %>
Rails - will_paginate gem not working when using .each do
It should be
<% @orders.each do |order| %>
not
<% @customer.orders.each do |order| %>
Related Topics
No Route Found in Rspec Test for an Existing Route
Programming a Simple Irc (Internet-Relay-Chat) Client
Sorting an Array of Objects in Ruby by Object Attribute
Rspec Controller Testing - Blank Response.Body
How to Turn on SQL Debug Logging for Activerecord in Rspec Tests
Should I Specify Exact Versions in My Gemfile
How to Get Exit Status with Ruby's Net::Ssh Library
Testing for Empty or Nil-Value String
Why Must I Explicitly Call Self on Accessor When Using the Array Union Operator |= in Ruby
Rails 4 Use Application Helpers Inside Initializers
{|_, E| E.Length>1} What Is the Use of Underscore ( _ ) in Ruby
Implementing Dry-Run in Ruby Script
How to Capture Terminal Arrow Keys in Ruby