动态 Rails 助手(例如 link_to 方法、方法)
我想知道如何为我的 Rails 助手获得一些动态能力:
<h3><%= link_to object.name, ("#{object.class_path.to_s}")_path(object) %></h3>
在这种情况下,将对象的类放入链接中。我对如何在辅助方法中抛出方法感到困惑。
任何建议将不胜感激!
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.
Any advice would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在尝试链接到该对象的实例吗?
Rails 可以从中构造一个
#show
链接。您可以将
polymorphic_path
用于更复杂/嵌套的情况:...作为
edit_user_#{object.class}_path(@user,object)
的同义词You're trying to link to the instance of the object?
Rails can construct a
#show
link from that.You can use
polymorphic_path
for more complicated/nested situations:...as a synonym for
edit_user_#{object.class}_path(@user,object)
我似乎通过这样做解决了这个问题:
使用
url_for
而不是 Something_path 是否存在任何性能或可用性问题?有什么区别吗?I seem to have solved this by doing this instead:
Are there any performance or usability issues using
url_for
instead of something_path? Is there any difference at all?