错误的错误数量(1为0)错误?rails

时间:2022-04-05 00:10:03

I am having a problem with the object saving. I have this code in the bookmark model:

我对保存对象有问题。我在书签模型中有这个代码:

class Bookmark
  include Mongoid::Document
  include Mongoid::Timestamps
  field :owner_req, type: Mongoid
  field :request_id, type: Mongoid
  field :corsponding_requests, type: Array

  belongs_to :user
  belongs_to :request
class << self

    def createBookmark ( title)
      bookmark = self.new
      bookmark[:owner_req] = title[:owner_req] #Here's the error
      bookmark[:request_id] = title[:request_id]
      bookmark[:corsponding_requests] = Array.new
      bookmark[:corsponding_requests].push(*title[:corsponding_requests])
      asd
       if bookmark.save
          bookmark
       end
    end

    def getBookmark(t)
      bookmark = find(t)
      if bookmark
        bookmark
      end
    end
    def getAll
      bookmark = self.all
      if bookmark
        bookmark
      end
    end
  end
end

request_bookmarked function

request_bookmarked函数

  bookmark = Hash.new
      req = User.find(session[:user])

      bookmark["owner_req"] = req[:id]
      bookmark["request_id"] = bookmarked_against_Request[:id]
      bookmark["corsponding_requests"] = Array.new
      bookmark["corsponding_requests"] <<  request_bookmarked[:_id]
      Bookmark.createBookmark(bookmark)
      if request_bookmarked[:favourites_of] == nil
        request_bookmarked[:favourites_of] = Array.new
        request_bookmarked_2[:favourites_of] = Array.new
      end
      if bookmarked_against_Request_2[:favourites] == nil
        bookmarked_against_Request_2[:favourites] = Array.new
        bookmarked_against_Request[:favourites]= Array.new
      end
      bookmarked_against_Request_2[:favourites] << request_bookmarked[:_id]
      request_bookmarked[:favourites_of] << bookmarked_against_Request_2[:_id]
      flash[:notice] = "Request has been bookmarked successfully."
    end
    request_bookmarked.update(Hash['favourites' ,request_bookmarked_2[:favourites]])
    bookmarked_against_Request.update(Hash['favourites' ,bookmarked_against_Request_2[:favourites]])

I have tried self.new (title) but it still keeps on giving me error.

我有试着自我。新的(标题)但它仍然不断给我错误。

Here's the screen shot to my error: error screenshot http://i62.tinypic.com/sf81le.jpg

这是我错误的屏幕截图:错误截图http://i62.tinypic.com/sf81le.jpg。

> ArgumentError - wrong number of arguments (1 for 0): ()
> home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/mongoid-1a7bbaabf1f0/lib/mongoid/fields/standard.rb:10:in
> `mongoize'   ()
> home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/mongoid-1a7bbaabf1f0/lib/mongoid/attributes.rb:291:in `typed_value_for'   ()
> home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/mongoid-1a7bbaabf1f0/lib/mongoid/attributes.rb:174:in `block in write_attribute'   ()
> home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/mongoid-1a7bbaabf1f0/lib/mongoid/threaded/lifecycle.rb:26:in
> `_assigning'   ()
> home/gardezi/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/bundler/gems/mongoid-1a7bbaabf1f0/lib/mongoid/attributes.rb:170:in `write_attribute'  app/models/bookmark.rb:14:in `createBookmark' 
> app/controllers/requests_controller.rb:217:in `bookmark_request' 
> actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in
> >`send_action'  actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'  actionpack
> (4.2.0) lib/action_controller/metal/rendering.rb:10:in
> >`process_action'  actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in >process_action' 
> activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call' 
> activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in
> >halting_and_conditional'  activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in
> >halting_and_conditional'  activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in >halting'

1 个解决方案

#1


0  

thanks you people for your time but I solved my problem. The owner request was to changed to user_id because when I write belongs_to :user it will assume that the attribute name is user_id

谢谢你们的时间,但我解决了我的问题。所有者请求被更改为user_id,因为当我写入belongs_to:user时,它将假设属性名是user_id。

#1


0  

thanks you people for your time but I solved my problem. The owner request was to changed to user_id because when I write belongs_to :user it will assume that the attribute name is user_id

谢谢你们的时间,但我解决了我的问题。所有者请求被更改为user_id,因为当我写入belongs_to:user时,它将假设属性名是user_id。