在我的部分模板中,有一个名为“resource”的变量,它可能是一个问题或答案。如何创建一个restful资源的“编辑”网址?
我想建立一个链接编辑它,但是当我使用它,我不知道它是什么,所以我不能写:
<%=link_to 'edit', edit_question_url(resource)%>
或
<%=link_to 'edit', edit_answer_url(resource)%>
我不知道是否有这样的方法,说:“url_for_edit()”,可作为:
<%=link_to 'edit', url_for_edit(resource)%>
有没有这样的方法?随着应用程序引发的异常,如果resource
无效,第一种方法
def edit_question_or_answer_url(resource)
send "edit_#{resource.class.name.underscore.pluralize}_url".to_sym, resource
end
:
感谢您的回答,这正是我想要的 – Freewind 2010-06-16 12:50:55