【问题标题】:Twitter Bootstrap error when running 'bootstrap:themed', with Mongo使用 Mongo 运行“bootstrap:themed”时出现 Twitter Bootstrap 错误
【发布时间】:2012-12-25 19:14:37
【问题描述】:

当我尝试在终端中运行 rails g bootstrap:themed Associations 时会发生这种情况:

C:/Users/ruby/.pik/rubies/Ruby-193-p327/lib/ruby/gems/1.9.1/gems/twitter-bootstrap-rails-2.1.9/lib/generators/bootstrap/themed/themed_generator.rb:87:in `block in retrieve_columns': undefined method `columns' for Association:Class (NoMethodError)

它似乎无法正常工作,我尝试了很多方法,到处搜索,从未成功。我正在使用 Mongo。

【问题讨论】:

    标签: ruby-on-rails mongodb twitter-bootstrap twitter-bootstrap-rails


    【解决方案1】:

    我刚刚得到完全相同的错误。我创建了两个相同的项目——一个有 mongoid,一个没有。我只收到关于 mongoid 项目的错误。

    找到了似乎可以解决问题的解决方法:

    删除文件中对 ActiveRecord 的引用(大约第 87 行):

    /home/ubuntu/.rvm/gems/ruby-1.9.3-p327/bundler/gems/twitter-bootstrap-rails-b8b7eb22614a/lib/generators/bootstrap/themed/themed_generator.rb
    

    我变了……

      def retrieve_columns
        if defined?(ActiveRecord)
          rescue_block ActiveRecord::StatementInvalid do
            @model_name.constantize.columns
          end
        else
          rescue_block do
            @model_name.constantize.fields.map {|c| c[1] }
          end
        end
      end
    

    到这个...

      def retrieve_columns
          rescue_block do
            @model_name.constantize.fields.map {|c| c[1] }
          end
      end
    

    为了让视图正常工作,我需要确保我的模型类有一个不为 nil 的 created_at 字段(或者编辑生成的视图)。

    希望这会有所帮助。

    PS:哇……看来你已经在 Windows 上运行了 twitter-bootstrap-rails - 我不知道这是可能的!

    【讨论】:

    • 是的,呵呵,现在我也在使用 Ubuntu……我实际上是通过将 twitter-bootstrap-rails 降级到“2.0.2”来让它工作的,但也许它不是永久修复所以我会试试你的解决方法!非常感谢!
    • 酷 - 很高兴听到。我会将链接发送给 twitter-boostrap-rails 维护者,以便他们找到独立于 ActiveRecord 的永久解决方案。
    猜你喜欢
    • 2016-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-01
    • 2014-05-06
    • 2013-10-30
    相关资源
    最近更新 更多