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
Related
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
This is basically a rails 3 version of this question. Short of parsing it myself, how can I get the components (controller, action, parameters) from a URL string?
The method ActionController::Routing::Routes#recognize_path has been deprecated, and I can't get the one it's been replaced with to work the same way:
1.9.3p125 :019 > ActionDispatch::Routing::RouteSet.recognize_path('/accounts/new', {:method => :get})
NoMethodError: undefined method `recognize_path' for ActionDispatch::Routing::RouteSet:Class
which makes sense since it's not a static method. Looking at the source didn't enlighten me either. Any pointers would be welcome.
EDIT:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Rails 3.2.3
This works for me (Ruby 1.9.2, Rails 3.1.0):
Rails.application.routes.recognize_path('/accounts/new', {:method => :get})
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.
I am using the rails3-amf gem by warhammerkid in my Rails 3 / Flex 4 project.
AFAIK, I have correctly followed the "Getting Started" instructions from the GitHub page.
I have added the gem lines to my Gemfile.
I have installed the gems using bundle install.
From my Flex application, I will be making the RemoteObject call to the index action in the ManageMySchool::GradesController file. This is the code in the app/controllers/manage_my_school/grades_controller.rb file:
class ManageMySchool::GradesController < ApplicationController
respond_to :html, :amf
def index
#grade = Grade.first
respond_with(#grade) do |format|
format.amf { render :amf => #grade.to_amf }
end
end
end
The name of the model which is to be serialized is called Grade in both the Rails project (app/models/Grade.rb) and the Flex project (Grade.as with a RemoteAlias set as Grade). In the config/application.rb file, I have done the class mapping this way:
config.rails3amf.class_mapping do |m|
m.map :as => 'Grade', :ruby => 'Grade'
end
And I have done a parameter mapping this way:
config.rails3amf.map_params :controller => 'ManageMySchool::GradesController', :action => 'index', :params => [:authenticity_token]
Problem
Now, when I run the server and make the RemoteObject call from Flex, I get a to_amf undefined method error for the Grade model.
If I change Grade.first to Grade.all, #grade would have an array of Grades. But the undefined method error message still mentions the Grade model. This means that the to_amf method is working for the Array class but not for the ActiveRecord model.
Why is this? What am I doing wrong?
Is there something I have to do to "enable" the rails3-amf gem for ActiveRecord models?
I would appreciate any insights. Thanks!
Update
#warhammerkid: Here is the output of Grade.ancestors as seen in rails console.
ree-1.8.7-2011.03 :006 > puts Grade.ancestors
Grade
ActiveRecord::Base
Paperclip::CallbackCompatability::Rails3::Running
Paperclip::CallbackCompatability::Rails3
Paperclip::Glue CanCan::ModelAdditions
Authlogic::ActsAsAuthentic::ValidationsScope
Authlogic::ActsAsAuthentic::SingleAccessToken
Authlogic::ActsAsAuthentic::SessionMaintenance
Authlogic::ActsAsAuthentic::RestfulAuthentication::InstanceMethods
Authlogic::ActsAsAuthentic::RestfulAuthentication
Authlogic::ActsAsAuthentic::PersistenceToken
Authlogic::ActsAsAuthentic::PerishableToken
Authlogic::ActsAsAuthentic::Password
Authlogic::ActsAsAuthentic::MagicColumns
Authlogic::ActsAsAuthentic::Login
Authlogic::ActsAsAuthentic::LoggedInStatus
Authlogic::ActsAsAuthentic::Email
Authlogic::ActsAsAuthentic::Base
ActiveRecord::Aggregations
ActiveRecord::Transactions
ActiveRecord::Reflection
ActiveRecord::Serialization
ActiveModel::Serializers::Xml
ActiveModel::Serializers::JSON
ActiveModel::Serialization
ActiveRecord::AutosaveAssociation
ActiveRecord::NestedAttributes
ActiveRecord::Associations
ActiveRecord::AssociationPreload
ActiveRecord::NamedScope
ActiveModel::Validations::Callbacks
ActiveRecord::Callbacks
ActiveModel::Observing
ActiveRecord::Timestamp
ActiveModel::MassAssignmentSecurity
ActiveRecord::AttributeMethods::Dirty
ActiveModel::Dirty
ActiveRecord::AttributeMethods::TimeZoneConversion
ActiveRecord::AttributeMethods::PrimaryKey
ActiveRecord::AttributeMethods::Read
ActiveRecord::AttributeMethods::Write
ActiveRecord::AttributeMethods::BeforeTypeCast
#<Module:0x1028356f0> ActiveRecord::AttributeMethods::Query
ActiveRecord::AttributeMethods
ActiveModel::AttributeMethods
ActiveRecord::Locking::Optimistic
ActiveRecord::Locking::Pessimistic
ActiveRecord::Validations
ActiveModel::Validations::HelperMethods
ActiveModel::Validations
ActiveSupport::Callbacks
ActiveModel::Conversion
ActiveRecord::Persistence Object
PP::ObjectMixin Base64::Deprecated
Base64
ActiveSupport::Dependencies::Loadable
Kernel
Note that only ActiveModel::Serialization is there. No mention of Rails3AMF.
Does this mean I have to do something special to load the Rails3AMF module for the ActiveRecord models?
I am using Rails 3.0.5 with the latest version of ree. The gems are all contained in a gemset managed using rvm.
Update 2
If I remove the to_amf in the render :amf line, then I get the following error:
Grade Load (0.3ms) SELECT `grades`.* FROM `grades` LIMIT 1
Completed 200 OK in 195ms (Views: 0.1ms | ActiveRecord: 0.8ms)
Sending back AMF
NoMethodError (You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.last):
Rendered /Users/anjan/.rvm/gems/ree-1.8.7-2011.03#rb/gems/actionpack-3.0.5/lib/> > action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms)
Rendered /Users/anjan/.rvm/gems/ree-1.8.7-2011.03#rb/gems/actionpack-3.0.5/lib/> > action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.8ms)
Rendered /Users/anjan/.rvm/gems/ree-1.8.7-2011.03#rb/gems/actionpack-3.0.5/lib/> > action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (13.6ms)
Started POST "/amf" for 127.0.0.1 at Fri Apr 15 17:03:34 +0530 2011
Sending back AMF
Update 3
If I manually add the line include Rails3AMF::Serialization at the top of the Grade.rb model file, then it all works. So, does this mean that I have to put this line in all my models?
I see that this is already being done in line numbers 40 - 42 in the lib/rails3-amf/serialization.rb file of the gem:
# Hook into any object that includes ActiveModel::Serialization
module ActiveModel::Serialization
include Rails3AMF::Serialization
end
Why isn't this working? Should I force-load the gem when my application initializes or something?
Thanks!
Update 4 - Solved by this workaround
Okay, I just ended up adding this code block in an initializer:
class ActiveRecord::Base
include Rails3AMF::Serialization
end
And it is working.
#warhammerkid - Thanks for the help.
Rails3AMF::Serialization, the module that adds the to_amf method, is included in ActiveModel::Serialization when Rails3-AMF loads. If it's somehow not being included even though the code is running and ActiveModel::Serialization is one of your model's ancestors, then the simplest solution is just to add "include Rails3AMF::Serialization" at the top of your model implementation. I've never tried gem sets before, but it might be an issue with them, as everything works correctly using Bundler.
As an aside, feel free to post a bug to https://github.com/warhammerkid/rails3-amf/issues.
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