0

RailsアプリでMongoidを使用しています。レール3.0.10ルビー1.9.2p0

「test」、「link」、「desc」などのフィールドを使おうとすると。

いう

Content.new(:test => 'ggg')

Content.new(:link => 'ggg')

Content.new(:desc => 'ggg')

コンテンツは「Mongoid::Document」を使用したモデルです

次のエラーが発生します。(このエラーはフィールド「テスト」用です)

mongoidは、フィールド名の上にあるコンテンツを関数として使用するライブラリを使用していると思います。

問題が発生する可能性があります。この問題を回避する方法はありますか?

ArgumentError: wrong number of arguments (0 for 2..3)
    from /usr/lib/ruby/gems/1.9.1/gems/activemodel-3.0.10/lib/active_model/dirty.rb:155:in `test'
    from /usr/lib/ruby/gems/1.9.1/gems/activemodel-3.0.10/lib/active_model/dirty.rb:155:in `attribute_will_change!'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes.rb:102:in `block (2 levels) in write_attribute'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes.rb:100:in `tap'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes.rb:100:in `block in write_attribute'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes.rb:170:in `assigning'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes.rb:98:in `write_attribute'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes/processing.rb:95:in `process_attribute'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes/processing.rb:25:in `block in process'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes/processing.rb:23:in `each_pair'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/attributes/processing.rb:23:in `process'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/document.rb:128:in `block in initialize'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/relations/builders.rb:47:in `building'
    from /usr/lib/ruby/gems/1.9.1/gems/mongoid-2.2.4/lib/mongoid/document.rb:125:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in `start'
    from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in `start'
    from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/commands.rb:23:in `<top (required)>'
    from /home/harshal/simple-cms/branches/1.0/script/rails:6:in `require'
    from /home/harshal/simple-cms/branches/1.0/script/rails:6:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'
4

1 に答える 1

1

最新のすべて、ruby(1.9.3)、rails(3.2.3)、mongoid(2.4.7)を使用して、次のことを試しました。

フィールドが設定されていないモデル、すべて動的:

class Content
  include Mongoid::Document
end

Railsコンソール:

1.9.3p125 :011 > c = Content.new(:test => "test", :link=> "link", :desc => "desc")
 => #<Content _id: 4f7f49f5add3617fae000003, _type: nil, test: "test", link: "link", desc: "desc"> 
1.9.3p125 :012 > c.save
 => true 
1.9.3p125 :013 > Content.first
 => #<Content _id: 4f7f49f5add3617fae000003, _type: nil, test: "test", link: "link", desc: "desc"> 
1.9.3p125 :014 >

すべてのフィールドが静的に設定されたモデル:

class Content
  include Mongoid::Document
  field :test, :type => String
  field :link, :type => String
  field :desc, :type => String
end

Railsコンソールも:

Loading development environment (Rails 3.2.3)
1.9.3p125 :001 > c = Content.new
 => #<Content _id: 4f7f4652add3617ec4000001, _type: nil, test: nil, link: nil, desc: nil> 
1.9.3p125 :002 > c.test = 'tyler'
 => "tyler" 
1.9.3p125 :003 > c.save
 => true 
1.9.3p125 :004 > Content.first
 => #<Content _id: 4f7f4652add3617ec4000001, _type: nil, test: "tyler", link: nil, desc: nil>
于 2012-04-06T19:50:25.813 に答える