Rails:从控制台检查路径助手的输出 [英] Rails: Check output of path helper from console

查看:24
本文介绍了Rails:从控制台检查路径助手的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails 定义了一堆带有命名路由的魔法,它们为你的路由创建了帮助器.有时,尤其是对于嵌套路由,跟踪给定路由辅助方法调用将获得的 URL 可能会有些混乱.是否可以使用 Ruby 控制台查看给定的辅助函数将生成什么链接?例如,给定一个像 post_path(post) 这样的命名助手,我想看看生成了什么 URL.

Rails defines a bunch of magic with named routes that make helpers for your routes. Sometimes, especially with nested routes, it can get a little confusing to keep track of what URL you'll get for a given route helper method call. Is it possible to, using the Ruby console, see what link a given helper function will generate? For example, given a named helper like post_path(post) I want to see what URL is generated.

推荐答案

您可以直接使用 rake routes 显示它们.

You can show them with rake routes directly.

在 Rails 控制台中,您可以调用 app.post_path.这将适用于 Rails ~= 2.3 和 >= 3.1.0.

In a Rails console, you can call app.post_path. This will work in Rails ~= 2.3 and >= 3.1.0.

这篇关于Rails:从控制台检查路径助手的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆