Kaminari page_method_name configuration fails - ruby-on-rails

I have a Rails 4.2 framework and use Kaminari to paginate. Everything works great, but I want to test everything with Capybara, thus I run into the page conflict. So I wanted to rename the page_method_name of Kaminari and followed the guide from them:
$ bundle exec rails g Kaminari:config
This results in this file
app/config/initializers/kaminari_config.rb
Kaminari.configure do |config|
config.page_method_name = :plant
end
In which I simply uncommented the config.page_method_name and set it to :plant (as an example from the Kaminari docs to avoid any reserved method name conflicts for something like :kaminari_page).
Then I adjusted the appropriate controller to
def index
#q = Interaction.published.order(updated_at: :desc).limit(200).ransack(params[:q])
#selection = #q.result
#interactions = Kaminari.paginate_array(#selection).plant(params[:page]).per(10)
respond_to do |format|
format.html
format.js
end
end
I restarted everything and got this error when visiting the
undefined method `plant' for #Kaminari::PaginatableArray:0x00005568fb42ba30
Gemfile.lock:
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
I was then googling around and also added require 'kaminari' (which does not make so much sense, because I did not get the uninit constant error) and also included the Kaminari configure section into the class Application < Rails::Application inside config/application.rb.
Nothing worked, always the same error.

You show your files location as app/config/initializiers/kaminari_config.rb. If that is the actual location of your file it fully explains why the method doesn't exist. The location should be app/config/initializers/kaminari_config.rb. With the location you specified it wouldn't be automatically loaded when the app starts.
If the location you showed is just a type then that wouldn't be the cause, but if you didn't include Capybara into the global object, which you shouldn't be doing anyway, then you wouldn't have a name collision. Current versions of Capybara issue a warning when you do include it into the global object specifically for this reason.
Also is there any reason you're grabbing all the results and then paging them, rather than using the page (or plant) and per scopes that would be defined on Interaction?

Related

Undefined method `paginate' for ShopifyAPI::Product:Class

I'm creating a web based rails application.
Can't find what causes the problem as mentioned above.
I have gem 'shopify-kaminari', '~> 1.1'
I checked in rails console:
Kaminari::Helpers::HelperMethods.instance_methods
=> [:paginate, :link_to_previous_page, :path_to_prev_page, :link_to_prev_page, :link_to_next_page, :path_to_next_page, :page_entries_info, :rel_next_prev_link_tags]
gem list kaminari
* LOCAL GEMS *
kaminari (1.0.1)
kaminari-actionview (1.0.1)
kaminari-activerecord (1.0.1)
kaminari-core (1.0.1)
shopify-kaminari (1.1.0)
In my rails controller, I simply have:
ShopifyAPI::Product.paginate(per: 250, page: params[:page])
Other info:
ShopifyAPI::Product.first => returns record (means ShopifyAPI request works fine)....
but implementing the pagination with gem 'shopify-kaminari'
returns the above error.
Anyone who has an idea about this?
Instead of using ShopifyAPI::Product.paginate(per: 250, page: params[:page]) it should be ShopifyAPI::Product.all(per: 250, page: params[:page]) and use <%= paginate(#products) %> in view .

Empty form values are not included in params in Active Admin

Resource form contents:
form do |f|
f.inputs do
f.input :name
end
f.actions
end
I am using Rails 5 beta 3, here is Gemfile contents:
# Backend
gem 'activeadmin', github: 'activeadmin/activeadmin', branch: 'master'
Gemfile.lock contents:
GIT
remote: git://github.com/activeadmin/activeadmin.git
revision: f7483e3b8fcd74437b03c18fb658dac62a9fc62e
branch: master
specs:
activeadmin (1.0.0.pre2)
arbre (~> 1.0, >= 1.0.2)
bourbon
coffee-rails
formtastic (~> 3.1)
formtastic_i18n
inherited_resources (~> 1.6)
jquery-rails
jquery-ui-rails
kaminari (~> 0.15)
rails (>= 3.2, < 5.0)
ransack (~> 1.3)
sass-rails
sprockets (< 4)
Even attribute is included in permitted params:
permit_params :name
it's missing in params when I submit empty value and as a result name is not updated. Non-empty values work OK.
Same with select boxes.
After error occured, I tried to update Active Admin with:
bundle update activeadmin
but error still remains.
I tested it on simple rails form (generated by scaffold command) and formtastic outside of Active Admin resource, both options work, so it seems to be Active Admin problem.
Here is how I checked params content (also checked logs/development.log):
controller do
def update
abort params.inspect
end
end
So name is not presented even at this moment.
I posted issue here but no feedback till now.
Since you are using rails5.0.0beta2, you are probably also using rack 2.0.0.alpha.
This is caused by a bug in rack.
Until rack2.0.0 become stable, you can solve this bug by adding to the Gemfile:
gem 'rack', github: 'rack/rack'

unable to Set up Gravatar on my app

Trying to add Gravatar to my app
but get "could not find generator gravtastic" on the command line
added gem 'gravtastic'
ran bundle install
Using warden (1.2.3)
Using devise (3.1.2)
Using foreigner (1.6.1)
Installing gravtastic (3.2.6)
Using hike (1.2.3)
Using jbuilder (1.0.2)
Using jquery-rails (3.0.4)
Using subexec (0.2.3)
restarted server
rails g gravtastic:install
Could not find generator gravtastic
Do you need to run a generator?
I think you just have to do:
class User < ActiveRecord::Base
include Gravtastic
gravtastic
end
The documentation doesn't mention the gravtastic generator.

activerecord-import gem NoMethodError: undefined method 'import'

I'm trying to use the activerecord-import gem and I've followed the directions on the wiki to a tee but I'm getting a NoMethodError: undefined method 'import' for #<Class:0x8b009b0>. Here's my code (basically the same as the example from the wiki)
class ExampleCode
def self.testing
orders = []
10.times do |i|
orders << Order.new(:raw_data => "order #{i}")
end
Order.import orders
end
end
I call the method like so:
ExampleCode.testing
I've tried on windows, linux, with a sqlite database, a mysql database and still no luck. And I'm certain I have the gem installed:
actionmailer (3.2.6, 3.2.3, 3.2.1, 3.2.0)
actionpack (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activemodel (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord (3.2.6, 3.2.3, 3.2.1, 3.2.0)
activerecord-import (0.2.10)
activerecord-oracle_enhanced-adapter (1.4.1)
activerecord-sqlserver-adapter (3.2.1)....
I even tried to use require (which shouldn't be necessary when the gem is installed. I haven't seen this come up anywhere else so I fear I must to missing something very obvious
You'll have to import active_record and activerecord-import
i.e.
require active_record
require activerecord-import
(as mentioned in the wiki)
The reason being, ruby won't know about it unless you explicitly import those libraries. In case of a rails project, rails imports all gems mentioned in the Gemfile for you.
I ran into the same thing; turns out that for me at least I had the gem included within a test block in the gemfile. make sure that when you include it it's not just limited to one app environment in the gem file.

Why is `layout nil` not working?

I just upgraded my Rails site from Rails 2 to Rails 3.2.
On my old controller I had:
class Foo::BarController < ApplicationController
layout nil
...
end
However now that I upgraded to Rails 3 it seems I need to change that to:
layout false
The documentation on Rails Guides claims that layout nil should work fine:
Layout declarations cascade downward in the hierarchy ...
class OldPostsController < SpecialPostsController
layout nil
I have the following relevant gems in my Gemfile.lock
GEM
actionpack (3.2.6)
activemodel (= 3.2.6)
activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
builder (3.0.0)
erubis (2.7.0)
haml (3.1.6)
jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
Is this a documented change somewhere, or is it a related gem monkey patching something?
The API explains it like this:
If the specified layout is:
a string: the string is the template name
a symbol: call the method specified by the symbol, which will return the template name
false: there is no layout
true: raise an ArgumentError
nil: force default layout behavior with inheritance
So the meaning of nil changed from no layout to "force default layout behavior with inheritance". Seems the explanation in Rails Guides is incorrect.

Resources