0

我有一個很難作出MongoMapper & Formtastic一起工作。未定義的方法`作用域」型號:類具有Formtastic和MongoMapper

在努力找出問題,我已經創建了代碼的最低限度的虛擬應用程序。

我有兩個主要型號(Cabinet & Device),它們之間有「many/belongs_to」關係,並且是一個用於Cabinet資源的腳手架控制器。

當我加載一個非常基本的formtastic形式(見下文),而不是簡單的「key」字段聲明時,我在控制器中收到一個「NoMethodError」異常,出現以下錯誤「未定義方法scoped」 Device:Class「引用_form.html.haml部分的第4行。

對此有何想法?沒有找到通過谷歌或StackOverflow的有用的東西......

應用程序/模型/ cabinet.rb

class Cabinet 
    include MongoMapper::Document 
    safe 

    key :label, String, :required => true 
    many :devices 
end 

應用程序/模型/ device.rb

class Device 
    include MongoMapper::Document 
    safe 

    key :label, String, :required => true 
    belongs_to :cabinet 
end 

應用程序/意見/cabinet/_form.html.haml

= semantic_form_for @cabinet do |f| 
    = f.inputs do 
    = f.input :label 
    = f.input :devices 
    = f.actions 

我沒有包括腳手架控制器,因爲我沒有以任何方式觸摸腳手架代碼。使用

寶石版本:

Gems included by the bundle: 
    * actionmailer (3.2.7) 
    * actionpack (3.2.7) 
    * activemodel (3.2.7) 
    * activerecord (3.2.7) 
    * activeresource (3.2.7) 
    * activesupport (3.2.7) 
    * arel (3.0.2) 
    * bson (1.6.4) 
    * bson_ext (1.6.4) 
    * builder (3.0.0) 
    * bundler (1.1.5) 
    * coffee-rails (3.2.2) 
    * coffee-script (2.2.0) 
    * coffee-script-source (1.3.3) 
    * erubis (2.7.0) 
    * execjs (1.4.0) 
    * formtastic (2.2.1) 
    * haml (3.1.6) 
    * haml-rails (0.3.4) 
    * hike (1.2.1) 
    * hpricot (0.8.6) 
    * i18n (0.6.0) 
    * journey (1.0.4) 
    * jquery-rails (2.0.2) 
    * json (1.7.4) 
    * libv8 (3.3.10.4) 
    * mail (2.4.4) 
    * mime-types (1.19) 
    * mongo (1.6.4) 
    * mongo_mapper (0.11.2) 
    * multi_json (1.3.6) 
    * plucky (0.5.1) 
    * polyglot (0.3.3) 
    * rack (1.4.1) 
    * rack-cache (1.2) 
    * rack-ssl (1.3.2) 
    * rack-test (0.6.1) 
    * rails (3.2.7) 
    * railties (3.2.7) 
    * rake (0.9.2.2) 
    * rdoc (3.12) 
    * ruby_parser (2.3.1) 
    * sass (3.1.20) 
    * sass-rails (3.2.5) 
    * sexp_processor (3.2.0) 
    * sprockets (2.1.3) 
    * therubyracer (0.10.1) 
    * thor (0.15.4) 
    * tilt (1.3.3) 
    * treetop (1.4.10) 
    * tzinfo (0.3.33) 
    * uglifier (1.2.7) 

回答

0

mongomapper不具備 「作用域」 類方法。這是ActiveRecord和Mongoid的一個特性。

+0

感謝您的回答。事實上,我正在與mongoid合作。 我仍然對此感到困惑,因爲我在Google上看到了很多鏈接,指出MongoMapper實際上可以和Formtastic一起使用。 現在我仍然認爲我已經搞砸了,並繼續搜索。 – 2012-08-07 21:10:34

+0

也有作用域現在已被棄用在rails 4下。但formtastic仍然呼籲我! – light24bulbs 2014-07-31 23:31:07

相關問題