views:

37

answers:

3

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
A: 

Maybe something like:

eval("#{done_event.class.to_s.underscore}_path(done_event)")
Yannis
what's teh diff between eval versus send, which si what I was using?
Angela
nopt, doesn't work...it evalutes done_event as an object, so it comes out contact_email.<object>
Angela
Then just put the id instead: eval("#{done_event.class.to_s.underscore}_path(#{done_event.id})")
Yannis
A: 

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)
Phyo Wai Win
but I don't know whether it is contadt_emails or contadt-calls ...that's why it's dynamic
Angela
It will still be fine. Just pass the class name you like
Phyo Wai Win
Sorry I have pressed the wrong key.. I was saying that you should try passing the class name in the method likepolymorphic_url([done_event.class.name, done_event])You might need to make the class name plural to make it work. It's worth testing it, I guess.
Phyo Wai Win
I will try that ... I did get it to work using send, its messier what is the interpretation of polymorphic_url -- does it mean it will take the first arg and call that the arg_path and the second is passed in?
Angela
Please check my edited answer for that. If you ever need to generate a url/path dynamically when you don't know the class of the object, you should just use polymorphic_url. e.g. polymorphic_url(post) # => "http://example.com/posts/1"
Phyo Wai Win
A: 

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.

Angela