Undefined method `paginate' for ShopifyAPI::Product:Class - ruby-on-rails

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 .

Related

Kaminari page_method_name configuration fails

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?

Pagination issue: `map' : undefined method 'existent'

I just installed the will_paginate, 3.0.7 and bootstrap-will_paginate, 0.0.10 gem and when i call the following to get my articles paginated
def index
#articles = Article.paginate(page: params[:page], per_page: 5)
end
I get the following error upon attempting to launch the localhost server
/Users/Jack/.rvm/gems/ruby-2.3.1#global/gems/activesupport-5.0.0.1/lib/active_support/i18n_railtie.rb:45:in `map': undefined method `existent' for #<String:0x007fd4a2bfa5d0> (NoMethodError)
Did you mean? extend
What's going wrong?
This was an issue with earlier version of will_paginate with Rails 5.
You need to update your will_paginate gem to use latest updated one which is:
gem 'will_paginate', '3.1.5'
This issue has been fixed with this merge:
https://github.com/mislav/will_paginate/pull/450

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'

Pry Remote / ByeBug next goes into Teardown

So I've decided to split my last post since the bug is Related to ByeBug more than to Pry-Remote (I think). Last post URL: Pry-Remote not triggered Rails 4
Problem:
When typing Next in Pry-Remote, ByeBug acts unexpectedly and goes to "teardown".
Also created an ByeBug Issue:
https://github.com/deivid-rodriguez/pry-byebug/issues/78
What I am running:
gem 'pry-byebug', '=1.3.3'
gem 'pry-stack_explorer'
gem 'pry-rails'
gem 'pry-remote'
pry (0.10.2)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (1.3.3)
byebug (~> 2.7)
pry (~> 0.10)
pry-rails (0.3.4)
pry (>= 0.9.10)
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
pry-stack_explorer (0.4.9.2)
binding_of_caller (>= 0.7)
pry (>= 0.9.11)
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
Rails 4.2.4
Note 1:
Updated all the pry related gems
https://gist.github.com/YOUConsulting/65cdcdc22d32780dde51
You seem to be using an ancient version of pry-byebug, the latest as of this writing is 3.2.0 but you're using 1.3.3. If you update your gems there's a good chance the problem will go away.
UPDATE
After further research it looks like pry-remote and pry-byebug do not work well together on Ruby 2.x.
However, there is a bit of code a coder posted, most of the comments are in Japanese, but they claim it makes pry-remote work. I'm including their code below (I've translated the Japanese as well):
module ObjectUtils
# remote parameter is the ip address, default port is 9876
def pry!(remote=nil, port=9876)
$LOAD_PATH.unshift "#{ENV['RUBY_PATH']}/debuger"
require 'pry'
return if __callee__ == :pry1 and !Pry.instance_variable_get(:#pry_is_start)
Pry.instance_variable_set(:#pry_is_start, true)
# if defined? Pry and defined? PryStackExplorer and Pry.config.hooks.hook_exists? :after_session, :delete_frame_manager
# Pry.config.hooks.delete_hook :when_started, :save_caller_bindings
# Pry.config.hooks.delete_hook :after_session, :delete_frame_manager
# end
if remote or ENV['USE_PRY_REMOTE']
if defined? PryNav
if defined? ActionDispatch # rails application.
if Pry.initial_session?
warn '[0m[33mloading pry remote ...[0m'
binding.of_caller(1).remote_pry(remote, port)
end
else
binding.of_caller(1).remote_pry(remote, port)
end
else
require_remote_debugger
binding.of_caller(1).remote_pry(remote, port)
`notify-send -t 5000 -- "exiting pry remote ..."` if find_executable 'notify-send'
end
else
# if these constants are defined then you're already in a debugger session
if defined? PryByebug or defined? PryDebugger or defined? PryNav
if defined? ActionDispatch # rails application.
if Pry.initial_session?
# When sending a new request, it will reset Pry.initial_sesssion? It is true.
# This ensures that, in the same request the debugger will be activated once.
# Only on the next request will it be reinitialized
warn '[1m[33mloading debugger ...[0m'
binding.of_caller(1).pry
end
else
binding.of_caller(1).pry
end
else
require_debugger
binding.of_caller(1).pry
end
end
end
def require_debugger
case RbConfig::CONFIG['ruby_version']
when '2.0.0'...'3.0.0'
require 'pry-byebug'
when '1.9.0'...'2.0.0'
require 'pry-debugger'
end
# to make sure the debugger is loaded
warn '[1m[33mloading debugger ...[0m'
require 'ap'; AwesomePrint.pry!
rescue LoadError
require 'pry-nav'
warn '[1m[33mloading debugger ...[0m'
end
def require_remote_debugger
require 'pry-remote'
require 'pry-nav'
warn '[0m[33mloading pry remote ...[0m'
`notify-send -t 10000 -- "loading pry remote ..."` if system 'which notify-send &>/dev/null'
require 'ap'; AwesomePrint.pry!
end
end
Kernel.send(:include, ObjectUtils)
Object.send(:include, Kernel)
You'll need to call these methods, and might need to tweak them for your usage.
References
https://github.com/Mon-Ouie/pry-remote/issues/58
https://github.com/Mon-Ouie/pry-remote/issues/35#issuecomment-20290739
https://github.com/deivid-rodriguez/pry-byebug/issues/33
https://rubygems.org/gems/pry-byebug

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.

Resources