Ruby On Rails Geokit gem geocoding returning nil - geokit

I am struggling with using the geokit gem in a Ruby on Rails application when supplied with an address to return anything other than nil.
I've read the previous articles here on Stack Overflow, the GitHub repo for the gem and other internet articles and I believe that I am following the examples.
This is code from my terminal window where I placed a binding.pry in my controller.rb file
20:
21: location_a = Geokit::Geocoders::GoogleGeocoder.geocode("140 Market St, San Francisco, CA")
22: location_b = GoogleGeocoder.geocode("140 Market St, San Francisco, CA")
23:
=> 24: binding.pry
25:
26: end
[1] pry(#<BrewsController>)> location_a
=> #<Geokit::GeoLoc:0x00007fa0d659f208
#all=[#<Geokit::GeoLoc:0x00007fa0d659f208 ...>],
#city=nil,
#country_code=nil,
#full_address=nil,
#lat=nil,
#lng=nil,
I read to put these at the top of my controller.rb file:
require 'geokit'
include Geokit::Geocoders
I have these lines of code in the config/initializers/geokit_config.rb file:
Geokit::Geocoders::GoogleGeocoder.api_key = "my-key-I-will-not-put-here"
Geokit::Geocoders::provider_order = [:google]
I have the gems installed:
/Users/slathyd/.gem/ruby/2.4.5/gems/geokit-1.13.1
/Users/slathyd/.gem/ruby/2.4.5/gems/geokit-rails-2.3.1
This is my Gemfile
gem 'geokit'
gem 'geokit-rails'
If anyone could tell me what I'm doing wrong and how to fix it, I would greatly appreciate it. Cheers.

The way I got the code to work was to simply restart everything. I had restarted my server several times, but I must have had to do something else. I shut it all down, the laptop, restarted the entire machine and it worked and has been working since. Thank you for all of those who looked at this and did research.

Related

Geokit Gem :Uninitialized Constant

so I just want to extract the longitude/latitude coordinates from a regular address(string). I went to geokit gem documentation and did precisely what was documented, yet I keep getting this error: "NameError: uninitialized constant Geokit::Geocoders::OpenSSL"
I added "geokit" to the gemfile and this:
require 'rubygems'
require 'geokit'
def get_coordinates
#a = Geokit::Geocoders::GoogleGeocoder.geocode '140 Market St, San Francisco, CA'
#a.ll
end
I've also tried adding this before, but to no avail.
Geokit::Geocoders::GoogleGeocoder.api_key = api_key
I just want coordinates, if this isn't a viable solution, can someone recommend another geocoder. I tried the railscasts but couldn't get that to work either. Any help would be greatly appreciated thanks!
Add
require 'openssl'
before
require 'geokit'.
Geokit does not automatically include the required OpenSSL gem.
I had the same problem with an old Rails app running on an old Ubuntu Lucid. I installed an old version of the geokit gem (1.5.0) and it worked.

SocketError (getaddrinfo: Name or service not known) - Sunspot/Solr Rails development

I have had lots of trouble with deploying my rails 3.0.10 application to Ubuntu 10.04 server with Passenger, Capistrano, nginx and MySQL (and even more trouble with apache2). After downgrading rake to 0.8.7 it's finally working, but now Sunspot/Solr doesn't work in my development environment. The sunspot_solr server is running, and I am able to get the server's url, and connect to it via the browser. The url is the same as in sunspot.yml. I have no idea what I have done that can have caused the problem. I had the same problem with sunspot earlier (before I downgraded rake). Then it suddenly started working again. I don't know why... I have tried two versions of Sunspot (1.2.1 and 1.3.0). Both have been working earlier, but not anymore.
This is the error message I'm getting:
SocketError (getaddrinfo: Name or service not known):
app/models/resource.rb:128:in `text_search'
app/controllers/search_controller.rb:21:in `index'
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (161.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (168.9ms)
The controller is a bit messy so I just include the relevant part:
#criterion = params[:criterion]
#sort_direction = params[:sort_direction]
if #criterion && #sort_direction
session["sort_search"] = #criterion + "|" + #sort_direction
elsif session["sort_search"]
#criterion = session["sort_search"].split("|")[0]
#sort_direction = session["sort_search"].split("|")[1]
else
#criterion = "updated_at"
#sort_direction = "desc"
end
#search = Resource.text_search(session[:search_params] || "", current_user, #criterion, #sort_direction)
#resources = #search.results
I have not changed anything in the controller since it was working.
My gemfile:
source 'http://rubygems.org'
gem 'rake'
gem 'rails', '3.0.10'
gem 'jquery-rails', '>= 1.0.12'
gem 'sqlite3'
gem 'ancestry'
gem 'carrierwave'
gem 'sunspot_rails', '>= 1.3' #'~> 1.2.1' #
gem 'authlogic'
gem 'will_paginate'
gem 'declarative_authorization'
group :production do
gem 'mysql'
end
group :development do
gem 'sunspot_solr'
end
gem 'capistrano'
My rakefile:
require File.expand_path('../config/application', __FILE__)
require 'rake'
Skolearkivet::Application.load_tasks
just a wild guess, any chance you are using localhost as the hostname? Try changing localhost to 127.0.0.1
I added this line to the top of file app/controllers/search_controller.rb
require 'resolv-replace'
Or alternatively you can put it to initializers/requires.rb
I've been having the same issue with rails and logstasher on OSX, couldn't figure out what was going on until I read this post. Thought I'd add this so that anyone else having the same kind of issue with logstasher can find something...
`=> Booting Unicorn
=> Rails 4.2.5 application starting in development on http://0.0.0.0:3000
=> Run rails server -h for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/xx/Projects/xx/config/environments/development.rb:80:in 'getaddress': getaddrinfo: nodename nor servname provided, or not known (SocketError)`
Fix was to add my machine hostname to the list under /etc/hosts for 127.0.0.1
I had a similar issue, which I worked around by editing the /etc/resolv.conf
before
nameserver 10.0.x.x
search example.com
after
#nameserver 10.0.x.x
nameserver 8.8.8.8
#search example.com
For me it was sufficient to remove the search line in my resolv.conf. My company inserted automatically it's own domain and my hostname was not a FQDN in my hosts file. This is a test environment obviously.
It could be that one of your third party service URLs is incorrect. For example, we had the wrong SMTP mail address. An exception within the app caused it to email the error to the admins and it failed with the error. Here's how you know when it's a bad address:
irb(main):009:0> Socket.gethostbyname("example.net")
SocketError: getaddrinfo: Name or service not known
I added this line
require 'resolv-replace'
to my controller file where the error was coming from and it worked for me. Hope it works for you too!

Devise not working after update, Tests via capybara complete without failures

I'm quite new to RoR and programmed a couple of things before discovering Test-Driven-Development. So I tried to write some tests with guard-rspec and capybara. All was fine, but I got some deprecation warnings for devise (had version 1.1.rc02), so I updated it (now having latest version 1.4.5).
These were the warnings:
Running all specs
DEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
FDEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_sessions_new_html_erb___942904761_2291541620_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/sessions/new.html.erb:3)
.DEPRECATION WARNING: Using form_for(:name, #resource) is deprecated. Please use form_for(#resource, :as => :name) instead. (called from _app_views_devise_registrations_new_html_erb__1735759005_2291086140_0 at /Users/xonic/Documents/work/ror.ror.at/app/views/devise/registrations/new.html.erb:3)
So I changed
<%= form_for(resource_name, resource, :url => registration_path(resource_name)) do |f| %>
to
<%= form_for(resource, :url => registration_path(resource_name)) do |f| %>
and got rid of the warnings. So far so good, I continued with my tests and did not try to open the application in the browser myself.
I'm not sure what happened then but all of a sudden, when trying to open the application in the browser, i get the following error message:
NoMethodError in Slides#index
Showing /Users/xonic/Documents/work/ror.ror.at/app/views/layouts/application.html.erb where line #27 raised:
private method `split' called for #<Class:0x10c023278>
Extracted source (around line #27):
24:
25: <div class="gopro">
26:
27: <% if user_signed_in? %>
28: Signed in as <%= link_to current_user.username, user_path(current_user) %>. Not you? <%#, user_slides_path(current_user.username) %>
29: <%= link_to "Sign out", destroy_user_session_path %>
30: <% else %>
So obviously, Devise is in trouble... no idea why. Funny thing is, when calling save_and_open_page while testing the app, a browser window opens with the application displaying correctly and no errors at all.
Guard::RSpec is running, with RSpec 2!
Running all specs
...
Finished in 0.95467 seconds
3 examples, 0 failures
UPDATE:
I've seen this very similar question Devise: NoMethod Error & user_signed_in and have correctly set up the user model, so that's not the problem.
This is quite confusing to me, hopefully someone out there understands what's happening crossingFingers
Thanks,
xon1c
UPDATE
I fixed it, but stackoverflow won't let me answer my own question in the next 6hrs because of lack of reputation sigh. Will post the solution later.
Ok, I fixed it (close to perfect). Here's what i did:
I reverted git to a working status and began from scratch. This time I did not use the line
gem 'devise', :git => 'git://github.com/plataformatec/devise.git'
in my Gemfile, instead I only put
gem 'devise'
and then installed the latest devise gem through
gem install devise
rails generate devise:install
The command installed version 1.4.5, not 1.4.7 as I previously had. Then I installed all the other gems, namely capybara, guard-rspec, factory_girl_rails and launchy. Everything works fine now except these two warnings I'm left with:
Running: spec/requests/sign_ups_spec.rb
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
DEPRECATION WARNING: :name_prefix was deprecated in the new router syntax. Use :as instead. (called from /Users/xonic/Documents/work/ror.ror.at/config/routes.rb:7)
.
Finished in 0.16255 seconds
1 example, 0 failures
Well, as long as everything works, I'm ok with the warnings but if anybody knows how to get rid of them, please let me know.
Thanks.

heroku rake require 'rake/dsl_definition' fix not working + breaking local rake

I'm having the same heroku rake issues described (and from what I can tell solved) in this question.
When I try the fix (include require 'rake/dsl_definition' above require 'rake') I get the same
'uninitialized constant Rake::DSL'
error from heroku + I get the error
'no such file to load -- rake/dsl_definition'
from my local rake.
Without incorporating the fix (using the standard rakefile) I can use rake on my local setup with no errors (with the same heroku error)
I'm using rake version 0.8.7 (though I get the same results using 0.9.2) and Rails 3.0.9. I've gone through the suggestions in the previous question but from what I can tell the problem isn't with my Gemfile. Has anyone else had this problem? Has anyone else solved their heroku rake problem using a different solution? Or can anyone explain/suggest how I'm going about this incorrectly?
Thank you for your help.
Try adding require 'rake/dsl_definition' on top of Rakefile.
Not enough for me. I was getting the no such file to load -- rake/dsl_definition error even adding the require 'rake/dsl_definition' line in the "Rakefile" file
I had all gems version OK and only 0.8.7 rake version but I had to create a "Gemfile" in the redmine root path with the next content:
gem "rake", "0.8.7"
And delete the require 'rake/dsl_definition' line added previously in Rakefile
Hope be usefull for someone

Latest Rails 3: ActionView::Template::Error (couldn't parse YAML at line 105 column 13)

I have recently encountered into a weird problem or Rails 3, possibly ever since the new rubygems 1.5 update. Basically when I deploy my program to nginx with passenger 3.0.2, I have 500 page immediately and problems like this in my production log:
ActionView::Template::Error (couldn't parse YAML at line 105 column 13):
10: </div>
11: <% end %>
12: <div class="field">
13: <%= f.label :name %> <%= f.text_field :name %>
14: </div>
15: <div class="field">
16: <%= f.label :password %> <%= f.password_field :password %>
app/views/sessions/new.html.erb:13:in `block in _app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
app/views/sessions/new.html.erb:5:in `_app_views_sessions_new_html_erb___4159562374589718885_19217640_4456777064017176818'
It looks like it's missing something in the environment and so it can't recognize all of my form_for elements. Basically the page is just a simple login page with 2 fields - name and password. This problem also happens for other pages with forms, but only in production environment. In development environment, it's totally working fine. I have upgraded all my gems to the latest version, including rails 3.0.4, which however looks like not quite related to this problem. I also used to deploy the same thing onto the ubuntu on my VMware BEFORE gem 1.5, everything is still fine now, however there's no turning back for the new deployments.
I have deployed this to 2 machines running latest ubuntu, and both machine have such errors. Nginx and passenger are installed with the standard steps. Obviously with this problem the site can never run. Can anyone provide any bug fix for this? Thanks very much if you could!
PS: the login page I wrote is basically from here:
http://railstutorial.org/chapters/sign-in-sign-out#top
I added the following two lines to the config/boot.rb file and the problem was solved.
require 'yaml'
YAML::ENGINE.yamler= 'syck'
I had the same problem. Actually I only needed the first line:
require 'yaml'
No need to set the YAML::Engine specifically.
For a problems with yaml syntax options like 'View/Show invisibles' in TextMate may be very helpful to locate syntax problems, yaml is very sensitive about it.
In my case I just had to replace all tabs with spaces in all locale files.
Also notice, if you don't have nodes with the same name on same level.