我使用了以下內容:如何使用動態類的.send方法轉到Rails中的特定路徑?
send("#{done_event.class.name.tableize}_path", done_event.id)
一個例子是done_event是ContactEmail的一個具體實例。
我想這代表了路徑contact_email_path(done_event.id),這將轉化爲類似contact_emails/1
但是,結果我得到的是contact_emails.1
不知道該怎麼辦...?
我也得到這個錯誤時,我只是嘗試在對象傳遞:
http://localhost:3000/contact_calls.%23%3Ccontactcall:0x9fefb80%3E
eval與send之間的差異是什麼,我在用什麼? – Angela 2010-10-08 07:35:38
nopt,不起作用...它將done_event當作一個對象來使用,所以它出來了contact_email。
然後只是把id改爲:eval(「#{done_event.class.to_s.underscore} _path(#{done_event.id})」) – Yannis 2010-10-08 11:54:38