开发者

How do I use the .send method for a dynamic class to go to the specific path in Rails?

开发者 https://www.devze.com 2023-01-19 04:52 出处:网络
I am using the following: send(\"#{done_event.class.name.tablei开发者_开发技巧ze}_path\", done_event.id)

I am using the following:

send("#{done_event.class.name.tablei开发者_开发技巧ze}_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


This seems to do the trick:

send("#{done_event.class.name.tableize.singularize}_path", done_event)

although if the polymorphic worked, i would like to use that.


Maybe something like:

eval("#{done_event.class.to_s.underscore}_path(done_event)")


Try polymorphic_url like this

polymorphic_url([:contact_emails, done_event])

EDIT: Since you don't know the class of 'done_event', all you have to do is pass like this.

polymorphic_url(done_event)
0

精彩评论

暂无评论...
验证码 换一张
取 消