(這可能是一個簡單的問題,但我沒有找到合適的語言來谷歌我的問題)數據庫查詢,保存模型變量控制器
在我的控制器我有這樣的查詢:
information = Event.where(name: 'xyz')
哪個工作正常。在這種情況下,只有模型「事件」被查詢,而不是其他模型,如「Blog」或「Post」。而不是寫每個查詢的,我只是想調用一個方法,這可能是這樣的:
def find_information (model, word)
information = model.where(name: 'word')
end
所以,如果我寫find_information (Event, xyz)
,它應該做的:
information = Event.where(name: 'xyz')
,或者如果我寫find_information (博客,XYZ),它應該做的:
information = Blog.where(name: 'xyz')
我嘗試這樣做:
model = Event
"#{model}".where(name: 'xyz')
但是,這引發了一個「未定義的方法」,其中'事件「:字符串」錯誤。如何將模型保存在變量中?在此先感謝