我試圖爲當前用戶創建一個搜索槽,但在傳入我的.find參數no implicit conversion of Symbol into Integer
時得到此錯誤。我將當前用戶參數存儲在@current_user中,並希望查找由該用戶編寫的所有文章(即在名爲user_id的列中搜索current_user.id)。我是新來的紅寶石,無法弄清楚這裏發生了什麼,谷歌搜索,任何幫助表示讚賞。Rails,當在表上使用.find時,沒有將Symbol隱式轉換爲Integer
應用控制器:
helper_method :current_user
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
文章控制器:
def manage
@article = Article.find(current_user.id[:user_id])
end
user.rb
class User < ActiveRecord::Base
attr_accessor :password
...
has_many :article
end
article.rb
class Article < ActiveRecord::Base
belongs_to :user
end
'current_user.id'是您要搜索的標識。即'@article = Article.find(current_user.id)'。 – Drenmi