如何使用动态类的 .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
I am using the following:
send("#{done_event.class.name.tableize}_path", done_event.id)
An example is done_event is a specific instance of ContactEmail.
I would like this to represent the path contact_email_path(done_event.id) which would translate to something like contact_emails/1
However, the result I get is contact_emails.1
Not sure what to do...?
I also get this error when I just try to pass in the object:
http://localhost:3000/contact_calls.%23%3Ccontactcall:0x9fefb80%3E
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎可以解决问题:
虽然如果多态有效,我想使用它。
This seems to do the trick:
although if the polymorphic worked, i would like to use that.
也许是这样的:
Maybe something like:
尝试 polymorphic_url 像这样
编辑:因为你不知道 'done_event' 的类,你所要做的就是像这样通过。
Try polymorphic_url like this
EDIT: Since you don't know the class of 'done_event', all you have to do is pass like this.