Newbie Rails Geocoder reverse search undefined error (Fresh project) - ruby-on-rails

I have created a fresh rails project. It's running on the lastest rails version as i have just installed rails on my pc and it is using Postgre for the DB. I have added the gem 'geocoder' in the gemfile and bundle install it. I have create a scaffold rails g scaffold location address:string latitude:float longtiude:float
I have added the following code into the location model file which I got from the official geocoder website http://www.rubygeocoder.com/
reverse_geocoded_by :latitude, :longitude,
:address => :location
after_validation :reverse_geocode
I then tried testing it, however it doesn't work. I have tried looking and reading the documentation but couldn't find any useful information. Could someone help pls.
I am getting the error of undefined method `location ....' when trying to save. This error is shown in the def create function
Parameters:
{"authenticity_token"=>"[FILTERED]", "location"=>{"address"=>"",
"latitude"=>"48.8582", "longitude"=>"2.2945"}, "commit"=>"Create
Location"}

Related

Geocoder gem 'rake geocode:all CLASS=Model' not working

I have a Ruby on Rails app with geocoder gem installed. I am trying to bulk geocode all rows (approx. 2500) in my database with rake geocode:all. When I run the command nothing happened. None of the rows were geocoded. Am I missing something here?
Model.rb
geocoded_by :fulladdress
after_validation :geocode
def fulladdress
[address, city, state, zip].compact.join(",")
end
Just try to run outside of the Rake task manually (e.g. rails console or rails runner):
Model.find_each {|m| m.save! }
If you do it in development have a quick look over the outputted SQL Statements, if there lines with "UPDATE models SET lat=?, lon=? ..."

Fuzzily: cannot get it to work

I am following the directions from the gem's GitHub repo:
I added fuzzily to my gem file and ran rake db:install. Fuzzily 0.3.3 was successfully installed.
I created a app/models/fuzzily.rb file:
class Trigram < ActiveRecord::Base
include Fuzzily::Model
end
I then created a migration for it:
class AddTrigramModel < ActiveRecord::Migration
extend Fuzzily::Migration
end
And ran: rake db:migrate, which created a trigrams table with the fields: id, trigram, score, owner_id, owner_type, fuzzy_field
I then modified my app/models/organization.rb and added the following:
fuzzily_searchable :org_name
I saved all my work and started the console:
rails c
then:
Lobbyist.connection
Followed by:
Lobbyist.bulk_update_fuzzy_name
To which I am getting an error message: undefined method .bulk_update_fuzzy_name
My environment is:
Ruby 2.1.5
Rails 4.2.1
Any ideas?
The name part in bulk_update_fuzzy_name is actually the name of the searchable field, so in your case it would be Lobbyist.bulk_update_fuzzy_org_name. The same applies to other method calls in the readme.

undefined local variable or method 'acts_as_gmappable'

I attempted to install the gmaps4rails gem.
I added gem 'gmaps4rails' to my Gemfile, and ran 'bundle install. It said that my bundle installed successfully. I can find "Using gmaps4rails (0.8.8)" with 'gem list'. I added the specified columns to my users table with rake db:migrate and added acts_as_gmappable and the gmaps4rails_address method to my User model.
Visiting pages that involve the user model gives me "undefined local variable or method 'acts_as_gmappable'"error.
Is there something that I am missing?
For greater context, the code I am using is from the Rails 3 Tutorial.
OS X 10.6.6
ruby 1.8.7
rails 3.0.7
passenger 3.0.7
Restarting the server should resolve the problem :)
I had the same issue : undefined local variable or method 'acts_as_gmappable'
I just restarted the server and it error went away.
I was using Mongoid and had the same trouble.
In which case, make sure your model includes:
include Gmaps4rails::ActsAsGmappable
acts_as_gmappable :position => :location
field :gmaps, :type => Boolean
field :location, :type => Array
def gmaps4rails_address
#describe how to retrieve the address from your model, if you use directly a db column, you can dry your code, see wiki
"#{self.address}, #{self.city}, #{self.country}"
end
I think this may be helpful (similar issue):
rvm + rails3 + gmaps4rails - acts_as_gmappable

Rails3 - oauth-plugin problem

I'm trying to use oauth-plugin on a Rails application I'm developing, but I keep running into problems.
To make sure I'm not making any mistake, I started an application from scratch (using Rails 3.0.3). Here are the steps I followed:
Create da new rails application (rails.test)
Edited its Gemfile to include:
gem "oauth-plugin", ">=0.4.0.pre1"
gem "oauth", "0.4.4"
Generated oauth-consumer, by running script/rails g oauth_consumer
Edited oauth_consumers.rb to include my keys for Google integration:
:google=>{
:key=>"anonymous",
:secret=>"anonymous",
:scope=>"https://www.google.com/calendar/feeds/",
:options => {
:site => "http://www.google.com",
:request_token_path => "/accounts/OAuthGetRequestToken",
:access_token_path => "/accounts/OAuthGetAccessToken",
:authorize_path=> "/accounts/OAuthAuthorizeToken"
},
}
Edited routes.rb to add the route for oauth_consumer:
resources :oauth_consumers
Edited application_controller.rb to implement the logged_in? method as follows:
def logged_in?
true
end
Now when I access http://localhost:3000/oauth_consumers/google I get the following error:
uninitialized constant GoogleToken
Does anyone know what causes this error and how can I fix it? GoogleToken is a class that should have been auto generated by oauth-plugin, so I can't tell why I'm getting this uninitialized constant error.
The GoogleToken class doesn't get auto-generated unless you pass "google" to the generator like so:
script/rails g oauth_consumer google
or for rails 3:
rails g oauth_consumer google
Also check to ensure the relationship is set up in the user model like so:
has_one :google, :class_name => "GoogleToken", :dependent => :destroy
Did you remember to run bundle install from terminal after editing your Gemfile? Sounds like your Rails app doesn't know about these gems yet.
I have the same problem, i think a solution could be in this:
https://github.com/pelle/oauth-plugin/blob/master/lib/generators/oauth_consumer/USAGE
You need some sort of authentication like restful-authentication plugin, if you uncomment line 27..29 in your oauth_consumers_controller.rb file, you'll jump to next step!

Rails validate_existence_of plugin

I'm reading the book Learning Rails by O'Reilly and it recommends using the validate_existence_of plugin. When I run:
ruby script/plugin install http: //svn.hasmanythrough.com/public/plugins/validates_existence/
it says it's already installed, but when I use it, I get a message saying:
NoMethodError in AwardsController#index
undefined method `validates_existence_of' for #<Class:0xb5fde868>
When I say:
class Award < ActiveRecord::Base
belongs_to :student
validates_existence_of :student
end
Any ideas?
Have you checked that the plugin code is installed in the vendor/plugins directory ?
Also you may need to check that the environment.rb file has the config.gem section uncommented.

Resources