【问题标题】:undefined local variable or method 'acts_as_gmappable'未定义的局部变量或方法'acts_as_gmappable'
【发布时间】:2023-03-16 18:00:02
【问题描述】:

我尝试安装 gmaps4rails gem。

我将gem 'gmaps4rails' 添加到我的Gemfile,然后运行'bundle install。它说我的包安装成功。我可以通过'gem list' 找到"Using gmaps4rails (0.8.8)"。我使用rake db:migrate 将指定的列添加到我的用户表中,并将acts_as_gmappablegmaps4rails_address 方法添加到我的User 模型中。

访问涉及用户模型的页面给我"undefined local variable or method 'acts_as_gmappable'"error。

我有什么遗漏的吗?

为了更详细的上下文,我使用的代码来自 Rails 3 教程。

OS X 10.6.6
红宝石 1.8.7
导轨 3.0.7
乘客 3.0.7

【问题讨论】:

  • 你应该运行bundle,然后运行bundle install。你在用 rvm 吗?
  • 您能否发布其余的相关代码,例如您的 user.rb 文件?
  • 安装gem后是否重启了服务器?
  • 哇,太尴尬了。看起来重启服务器是我所缺少的。
  • @ramc: 我想你应该发布你的答案:)

标签: ruby-on-rails ruby-on-rails-3 osx-snow-leopard gmaps4rails


【解决方案1】:

重启服务器应该可以解决问题:)

【讨论】:

    【解决方案2】:

    我有同样的问题:未定义的局部变量或方法'acts_as_gmappable'

    我刚刚重启了服务器,错误就消失了。

    【讨论】:

      【解决方案3】:

      我在使用 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
      

      【讨论】:

        【解决方案4】:

        我认为这可能会有所帮助(类似问题):

        rvm + rails3 + gmaps4rails - acts_as_gmappable

        【讨论】: