动态导轨助手(例如link_to方法,方法) [英] dynamic rails helpers (eg. link_to method, method)
本文介绍了动态导轨助手(例如link_to方法,方法)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何为我的导轨助手获得一些动态的能力:
I was wondering how to get some dynamic abilities for my rails helpers:
<h3><%= link_to object.name, ("#{object.class_path.to_s}")_path(object) %></h3>
在这种情况下,将对象的类投入到一个链接中。我很困惑如何在辅助方法中抛出一个方法。
In this case, throwing it the object's class into a link to. I'm getting confused on how to throw a method within a helper method.
任何建议将不胜感激!
推荐答案
您正在尝试链接到对象的实例?
You're trying to link to the instance of the object?
<%= link_to object.name, object %>
Rails可以构建一个 #show
链接
Rails can construct a #show
link from that.
您可以使用 polymorphic_path
进行更复杂/嵌套的情况:
You can use polymorphic_path
for more complicated/nested situations:
<%= link_to object.name, polymorphic_path([:edit, @user, object]) %>
...作为的同义词edit_user _#{object.class} _path (@ user,object)
这篇关于动态导轨助手(例如link_to方法,方法)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文