我正在尝试将数据保存在书签变量中,但它会抛出标题中描述的错误。请告诉我我做错了什么我无法理解错误。
bookmarks = Bookmark.where(request_id: bookmarked_against_Request[:_id])
if bookmarks
bookmarks[:corsponding_requests] << request_bookmarked[:id]
else
bookmarks_new = Hash.new
bookmarks["owner_req"] = session[:user]
bookmarks["request_id"] = data
bookmarks["corsponding_requests"] = Array.new
bookmarks["corsponding_requests"] << request_bookmarked[:_id]
Bookmark.createBookmark(bookmarks)
end
rails error http://i59.tinypic.com/290r8ft.png
PS: - 我已经改变了BOOKMARKS_NEW的标记,但仍然存在同样的错误
答案 0 :(得分:1)
试试这个:
bookmarks = Bookmark.where(request_id: bookmarked_against_Request[:_id])
if bookmarks
bookmarks.each { |bookmark| bookmark.update_attributes(corsponding_requests: request_bookmarked[:id] }
else
bookmark = Hash.new
bookmark["owner_req"] = session[:user]
bookmark["request_id"] = data
bookmark["corsponding_requests"] = Array.new
bookmark["corsponding_requests"] << request_bookmarked[:_id]
Bookmark.createBookmark(bookmark)
end
答案 1 :(得分:1)
你可以想象bookmarks
喜欢数组,当你尝试bookmarks[:corsponding_requests]
ruby&#34;想想&#34;时,你希望通过整数索引访问数组元素(例如{{1}但是它不能将符号转换为整数并抛出错误。也许,它可以帮助你...