我尝试安装gmaps4rails gem。
我将gem 'gmaps4rails'
添加到我的Gemfile中,然后运行'bundle install
。它说我的捆绑安装成功了。我可以使用"Using gmaps4rails (0.8.8)"
找到'gem list'
。我使用rake db:migrate
将指定的列添加到了我的用户表中,并将acts_as_gmappable
和gmaps4rails_address
方法添加到我的User
模型中。
访问涉及用户模型的网页会导致"undefined local variable or method 'acts_as_gmappable'"
错误。
我有什么遗失的东西吗?
对于更大的上下文,我使用的代码来自Rails 3 Tutorial。
OS X 10.6.6
红宝石1.8.7
rails 3.0.7
乘客3.0.7
答案 0 :(得分:13)
重新启动服务器应解决问题:)
答案 1 :(得分:1)
我遇到了同样的问题:未定义的局部变量或方法'acts_as_gmappable'
我刚刚重新启动服务器,它的错误就消失了。
答案 2 :(得分:1)
我使用Mongoid并遇到同样的麻烦。
在这种情况下,请确保您的模型包括:
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
答案 3 :(得分:0)
我认为这可能会有所帮助(类似问题):