Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an "edit" url for a restful resource?

In my partial template, there is a varible named "resource", it may be a question or an answer.

I want to build a link to edit it, but when I use it, I don't know what it is, so I can't write:

<%=link_to 'edit', edit_question_url(resource)%>

or

<%=link_to 'edit', edit_answer_url(resource)%>

I wonder if there is such a method, say "url_for_edit()", can be used as:

<%=link_to 'edit', url_for_edit(resource)%>

Is there such a method?

like image 561
Freewind Avatar asked Jan 22 '23 21:01

Freewind


1 Answers

you can try polymorphic_url(resource) prefixed with edit_polymorphic_url(resource) http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html

like image 67
dombesz Avatar answered Jan 28 '23 15:01

dombesz