Gardezi
Gardezi

Reputation: 2842

update function throwing erro(rails)

I am having a problem that when ever I call the update function it throws an error. I have tried to find the solution but I could'nt find it and I can't understad the error. Please tell me what is wrong with the code

The update function is called from this function

  def bookmark_request
    data = params[:d]
    request_bookmarked = Request.getRequest(data)
    bookmarked_against_Request = Request.first
    request_bookmarked_2 = request_bookmarked
    bookmarked_against_Request_2 = bookmarked_against_Request

    if bookmarked_against_Request_2[:favourites]
      bookmarked_against_Request_2[:favourites] << bookmarked_against_Request[:id]
    else
      bookmarked_against_Request_2[:favourites] = Array.new
      bookmarked_against_Request_2[:favourites] << bookmarked_against_Request[:id]
    end


    Request.updateRequest(bookmarked_against_Request , bookmarked_against_Request_2)
    redirect_to :action => "active"
  end

and the update code is this

def updateRequest(request,req_data)
 if request.update(req_data)
  request
 end
end

The error that I am getting is this

**NoMethodError at requests/bookmark_request

undefined method `empty?' for Request:0x007f3fa44c59b0**

The error always comes on the line if request.update(req_data)

Sice I do not have a reputation of 10 so I am posting links to screenshot of the error http://tinypic.com/r/whbiv7/8

Upvotes: 0

Views: 72

Answers (1)

Andrey Turkin
Andrey Turkin

Reputation: 719

update() method's argument is expected to be a hash. But your req_data argument becomes actually a Request here:

def bookmark_request
 bookmarked_against_Request = Request.first
 ...
 bookmarked_against_Request_2 = bookmarked_against_Request
 ...
end

And Request class has no empty? method. Moreover it might become nil, if there are no Requests at all.

Upvotes: 1

Related Questions