Pry Remote / ByeBug next goes into Teardown - ruby-on-rails

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

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?

Deprecation warning with "spring rspec" but not "rspec"

When I run spec via bundler, I get no errors...
bundle exec rspec -fd spec/controllers/blah.rb
But when I run it via the binstub to use spring, I get lots of these errors:
./bin/rspec -fd spec/controllers/blah.rb
DEPRECATION WARNING: `serialized_attributes` is deprecated without replacement, and will be removed in Rails 5.0.
Why is this?
I have tried stopping and starting; no effect.
In config/environments/test.rb I have this:
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
For reference...
$ bundle list | grep -E '(rspec|spring)'
* rspec-core (3.0.4)
* rspec-expectations (3.0.4)
* rspec-mocks (3.0.4)
* rspec-rails (3.0.2)
* rspec-support (3.0.4)
* spring (1.7.2)
* spring-commands-rspec (1.0.4)
As requested, my ./bin/rspec file...
$ cat ./bin/rspec
#!/usr/bin/env ruby
begin
load File.expand_path('../spring', __FILE__)
rescue LoadError => e
raise unless e.message.include?('spring')
end
# frozen_string_literal: true
#
# This file was generated by Bundler.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require "rubygems"
require "bundler/setup"
load Gem.bin_path("rspec-core", "rspec")
Well one possible fix is to change this:
config.active_support.deprecation = :stderr
to
config.active_support.deprecation = :silence
However this does not answer why its suppressed for rspec, not not via spring?!

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'

conflict between mongoid and mongo (mongo-ruby-driver)

I need to use the two gems mongoid and mongo in my Rails app.
Any ideas to workaround this troublesome problem thanks~
gem 'mongo', '2.0.2',:git => 'git://github.com/mongodb/mongo-ruby-driver.git'
gem 'mongoid', '4.0.0'
# gem "mongo_mapper"
Error message
Bundler could not find compatible versions for gem "bson":
In Gemfile:
mongo (= 2.0.2) ruby depends on
bson (~> 3.0) ruby
mongoid (= 4.0.0) ruby depends on
moped (~> 2.0.0) ruby depends on
bson (~> 2.2) ruby
UPDATE
Mongoid is handy , but sometime it is sucks,
because I got error 'Client Error: Remaining data too small for BSON object,
and even I wrapped it in begin rescue block , it still break my Rails app, and stop the import data task, what the suck Mongoid is ! So I decided to give up use Mongoid to insert new records to collection , I tried to use mongo. But they are conflict in my Rails app, WTH again !
def bulk_insert_to_collection(collection_name)
model = collection_name.capitalize.constantize.new
begin
model.collection.insert(#data_in_chunk)
# #bulk.execute
rescue Exception=>err
log_error "[#{err}] File #{#file_path}: line of #{i} #{Time.now}"
rescue Exception => err
log_error "[#{err}] File #{#file_path}: line of #{i} #{Time.now}"
rescue => err
p ex
log_error "[#{err}] File #{#file_path}: line of #{i} #{Time.now}"
end
# #data_in_chunk = []
end

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