undefined local variable or method 'acts_as_gmappable' - ruby-on-rails

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

Related

Newbie Rails Geocoder reverse search undefined error (Fresh project)

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"}

Spree Zone#zone_members.empty? returns incorrect value in spree 1.3.2

I noticed weird thing developing Spree application (I'm using Spree 1.3.2):
Spree uses model called Zone. Zone is associated with zone_members, like this:
has_many :zone_members, :dependent => :destroy, :class_name => "Spree::ZoneMember"
Strange part begins here, in rails console:
zone = Spree::Zone.first
zone.zone_members.empty?
# => true
zone.zone_members
# => []
zone.zone_members.reload.empty?
# => false
zone.zone_members
# => [#<Spree::ZoneMember id: 4914820, zoneable_id: 13, zoneable_type: ...
What's interesting this problem doesn't occur in Spree 1.3.3.
Apart from Spree, I use Rails 3.2.14 (or Rails 3.2.13 - the same result) and Ruby 1.9.3.
Does anybody know why does it happen?
I would guess that this was a bug that was fixed between Spree 1.3.2 and Spree 1.3.3. I highly recommend using 1.3.3, as that is the latest stable gem release from that branch and probably contains more than just that fix.

Rails migration error database_authenticatable

-- create_table(:admin_users)
rake aborted!
An error has occurred, this and all later migrations canceled:
undefined method `database_authenticatable' for #
Tasks: TOP => db:migrate
How to solv it? Thanx!
migration
create_table(:admin_users) do |t|
t.database_authenticatable :null => false
t.recoverable
t.rememberable
t.trackable
t.timestamps
end
have all gems in gemfile and installed
Make sure you have devise in the Gemfile and the bundle is installed.
Answer is simple device team sucks!!!
to solve this need make cnanges in GEMFILE
gem 'devise', "~> 1.5"
because in 1.5 there is database_authenticatable type support and in 2.1.0 there is support of only compatibility not creation of fields with this type
thanx everybody.
If you're just getting started with devise (vs updating from previous verions), you might have missed the following step before doing rake db:migrate
rails generate devise:install
This creates
create config/initializers/devise.rb
create config/locales/devise.en.yml
which define the method rake is complaining about above.
Source:
https://github.com/plataformatec/devise
With Devise 2.0 and newer, the migration helper methods (t.database_authenticatable for example) are not available (as stated on the wiki here ) If you're making a new model for users, just use the devise migration generator like so:
rails g devise admin_users (If you're installing devise on your app)
If you're adding the required fields to an existing user model, you should check this page on the devise wiki.
Check out the main README for devise, which has up-to-date information for installing the latest version of devise on Rails.

Rails 3 Authlogic acts_as_authentic undefined

I'm getting an error that acts_as_authentic is undefined for rails 3, ruby 1.9.2
My Gemfile has: gem 'authlogic'
The command "bundle show authlogic" shows the correct path where authlogic is installed
My acts_as_authentic appears in a controller:
class User < ActiveRecord::Base
acts_as_authentic do |c|
c.login_field = :phone
end
end
Let me know if there's anything else that will be helpful, I'm new to rails so I'm not entirely sure what to post.
Thanks
For some reason I always ask questions on StackOverflow just before I figure it out. I needed to restart rails server to get it to work.

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!

Resources