Ruby uninitialized constant Pipl::Person (NameError) - ruby-on-rails

I am trying to integrate the Pipl API into my ruby on rails application. I am using ruby version 2.3.4 and rails 4.2.5. As a reference i looked at
this site
and copied the ruby version of the code directly from it into a ruby file. When I run the ruby file in the terminal i get the error:
`<main>': uninitialized constant Pipl::Person (NameError)
Any ideas why I'm getting this error? Any help is greatly appreciated.
This is the code snippet that I used:
require 'pipl'
person = Pipl::Person.new
person.add_field Pipl::Name.new(first: 'Clark', last: 'Kent')
person.add_field Pipl::Address.new(country: 'US', state: 'KS', city:
'Smallville')
person.add_field Pipl::Address.new(country: 'US', state: 'KS', city:
'Metropolis')
response = Pipl::client.search person: person, api_key: 'myKEY' #I used my actual key here
puts "#{response}"
Thanks!

In order to use the Pipl API without the error, I got my API key through their site and I added piplapis-ruby gem just like what was told in the comments above. I imported all of the ruby classes found here: https://github.com/piplcom/piplapis-ruby into my project and pasted the codesnippet.rb file found here: https://github.com/piplcom/piplapis-ruby which was the ruby file you're supposed to execute. There was no need for me to create the Person class.

Related

CableReady (Rails) Basic case giving mystifying error message

cable_ready 4.5.0
rails 6.1.4.1
ruby 3.0.2p107
This is a simple example from the basic tutorial (https://www.youtube.com/watch?v=F5hA79vKE_E) I suspect the error I am getting is because either cable_ready or rails evolved a little and created a tiny incompatibility.
I get this error in the JS console:
It is triggered when in my controller I ask cable ready to:
cable_ready["timeline"].console_log(message: "***** cable ready post created")
Which leads to my timeline_channel to:
received(data) {
console.log("******** Received data:", data.operations)
if (data.cableReady) CableReady.perform(data.operations)
}
My interpretation is perform causes this line in cable_ready.js line 13:
operations.forEach(function (operation) {
if (!!operation.batch) batches[operation.batch] = batches[operation.batch] ? ++batches[operation.batch] : 1;
});
Is finding something in the received data that it doesn't like.
That's where my trail ends. Can someone see what I am doing wrong, or tell me what other code you'd like me to include?
Solution: downgrade the version of the cable_ready javascript library.
I previously (maybe a year ago) did this tutorial using CableReady 4.5, Ruby 2.6.5 and Rails 6.0.4 and it worked like a charm back then as well as today.
But today, I tried this tutorial again on a duplicate project--same versions of CR, Ruby, and Rails and now I get java console errors similar to yours.
TypeError: undefined is not a function (near '...operations.forEach...')
perform -- cable_ready.js:13
received -- progress_bar_channel.js:8
I looked at the output of yarn list and saw that cable_ready was version 5.0.0-pre8 on the bad project and it was 5.0.0-pre1 on the good project. The downgrade could be accomplished with yarn add cable_ready#^5.0.0-pre1 in the bad project folder and now both projects work.
FYI for other newbies like me trying to understand how CableReady works: This tutorial gives another example of CableReady, and was also fixed the same way.

Keep getting this error in Ruby on Rails: rake aborted! NameError: uninitialized constant Faker::Coffee

Trying to re-seed an existing Ruby on Rails application. Before, this exact same seed file worked but after db:dropping, db:creating, db:migrating, I can no longer seed my database using the db:seed. I keep getting this error,
"NameError: uninitialized constant Faker::Coffee"
I am using the Faker gem to populate my database and I used that successfully before, have bundle installed and updated my gemfile, but still no luck. Scoured this site and web but have found no solutions so far. Tried to not use faker and simply seed data using my own names but still got the same error as above, just with the name I wanted to use. I am stuck, any help is greatly appreciated. Thank you.
Here is my seed file for reference:
b = Menu.create(name: 'Breakfast')
l = Menu.create(name: 'Lunch')
d = Menu.create(name: 'Dinner')
ln = Menu.create(name: 'Late Night')
def add_menu_items(menu)
10.times do
menu.menu_items.create(
name: Faker::Coffee.blend_name,
description: Faker::Coffee.notes,
price: Faker::Number.between(5.50, 100.75)
)
end
end
add_menu_items(b)
add_menu_items(l)
add_menu_items(d)
add_menu_items(ln)
puts 'Menus Seeded'

"no implicit conversion of nil into String"in the Search Module of Redmine

On the redmine of my company, there is this bug where I get an internal error if I want to search into a project.
Here is the log corresponding to the error:
Processing by SearchController#index as HTML
Parameters: {"utf8"=>"✓", "issues"=>"1", "q"=>"test", "id"=>"sprint"}
Current user: me (id=60)
Completed 500 Internal Server Error in 85.0ms
TypeError (no implicit conversion of nil into String):
lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb:126:in `search'
app/controllers/search_controller.rb:74:in `block in index'
app/controllers/search_controller.rb:73:in `each'
app/controllers/search_controller.rb:73:in `index'
The lines corresponding to the error in the controller are :
if !#tokens.empty?
# no more than 5 tokens to search for
#tokens.slice! 5..-1 if #tokens.size > 5
#results = []
#results_by_type = Hash.new {|h,k| h[k] = 0}
limit = 10
#scope.each do |s|
r, c = s.singularize.camelcase.constantize.search(#tokens, projects_to_search,
:all_words => #all_words,
:titles_only => #titles_only,
:limit => (limit+1),
:offset => offset,
:before => params[:previous].nil?)
#results += r
Here is my config :
Environment:
Redmine version 2.6.9.stable
Ruby version 2.3.0-p0 (2015-12-25) [x86_64-linux]
Rails version 3.2.22
Environment production
Database adapter PostgreSQL
SCM:
Git 1.9.1
Filesystem
Redmine plugins:
no plugin installed
What is interesting is that when I search only one letter, i'm redirected on the search page, but I don't have an internal error.
I'm very new to Redmine developpement and to Ruby, I was just assigned to try to fix this bug. Do any of you have an idea of how to fix it ?
Thanks.
I had the same issue, I was able to fix it by downgrading my ruby & rails version, a working set is :
Rails 3.2.19
Ruby 2.1.4p265
It's look like it's due to a braking change in ruby-2.3.0.
It's really odd. We are using 'Redmine' -2.0.3.1 and we do not have that kind of behaviour.
It seems that "someone" messed up the form linked to the search input. Try to follow that data from when you press enter until it answer you with the 500 error code.
If you can , change the environment to development, this way it will show you more detailed errors.
But I can't help you much more , you didn't provide enough info about the problem.

Activesupport / Multi json: "Did not recognize your adapter specification"

I have a Ruby 1.9.3 / Rails 3.1 project with the following in the gemfile:
gem 'rails', '3.1.12'
gem 'json'
gem 'multi_json', '1.7.7'
That version of rails sets activesupport to 3.1.12 as well. I'm not sure what the exact cause of the problem is, but when running bundle exec rake test, I got the error:
/home/user/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json.rb:121:in 'rescue in load_adapter': Did not recognize your adapter specification. (ArgumentError)
...
(more stack trace, including activesupport methods)
Fortunately I found a solution! See below.
Edit: My original answer is outdated and incorrect; read it if you please, but please read the updated information at the bottom.
After viewing a ton of other questions such as these ones:
OmniAuth Login With Twitter - "Did not recognize your adapter specification." Error
Capistrano deploy: "Did not recognize your adapter specification" during assets:precompile
https://github.com/intridea/multi_json/issues/132
I hadn't found a solution, so I dove into the library and determined that load_adapter was receiving the parameter "JSONGem". The alias was failing, and the method attempted to load
/home/user/.gem/ruby/1.9.3/gems/multi_json-1.7.7/lib/multi_json/adapters/JSONGem.rb
This file doesn't exist, but .../json_gem.rb does exist! So I modified load adapter as follows:
def load_adapter(new_adapter)
# puts "new_adapter: #{new_adapter}" # Debugging
# puts "new_adapater.class: #{new_adapter.class}" # Debugging
case new_adapter
when String, Symbol
new_adapter = ALIASES.fetch(new_adapter.to_s, new_adapter)
new_adapter = "json_gem" if new_adapter =~ /^jsongem$/i # I added this line
# puts "final adapter: #{new_adapter}" # debugging
require "multi_json/adapters/#{new_adapter}"
klass_name = new_adapter.to_s.split('_').map(&:capitalize) * ''
MultiJson::Adapters.const_get(klass_name)
when NilClass, FalseClass
load_adapter default_adapter
when Class, Module
new_adapter
else
raise NameError
end
rescue NameError, ::LoadError
raise ArgumentError, 'Did not recognize your adapter specification.'
end
This fixed the problem for me. It's probably not an optimal solution (ideally I would understand WHY the ALIASES.fetch failed, if that is indeed what happened, and fix that), but if your problem is similar then hopefully this quick fix can help.
Update
It's not viable for deployability reasons to modify someone else's gem. Fortunately I found the root cause of the problem. In project_root/config/initializers/security_patches.rb, we had the line
ActiveSupport::JSON.backend = "JSONGem"
This was the recommended fix to a security bug in older versions of rails. Now that we are on a newer version of rails (i.e, > 3.0), we can simply replace "JSONGem" with "json_gem" (which is what my original modification was doing, in a roundabout way) and not worry about the security issue.

RSRuby installation and R configuration error

I tried to install RSRuby following the steps mentioned in http://web.kuicr.kyoto-u.ac.jp/~alexg/rsruby/manual.pdf and http://nsaunders.wordpress.com/2009/05/20/baby-steps-with-rsruby-in-rails/ and I must say that nsaunders blog is indeed a great start for anyone installing RSRuby. But when I tried to check from the irb by creating an instance of RSRuby:
r = RSRuby.instance
it returned me error:
1.8.7-p371 :001 > r = RSRuby.instance
NameError: uninitialized constant RSRuby
from (irb):1
I have all the prerequisites: R_HOME, shared lib option and other stuff. I dont know why I got this error. Any ideas guyzz?????
has anyone tried it for rails successfully???
Without seeing the full source code it's difficult to give you an answer, so this is just a guess. Did you remember to require 'rsruby' within your code? NameError is often caused when a gem is installed but the code does not include the appropriate require statement:
require 'rsruby'
r = RSRuby.instance
You can see this in the code example in the "Documentation" section of the README in the GitHub project.

Resources