在 Ruby on Rails 中,在视图中时,您可以在到达视图之前转储文件和行号吗?
第一层是路由,第二层是控制器,所以当在视图中时,有没有办法在到达视图之前转储路由和控制器的路径或文件名和行号?
我想这样做是因为 www.example.com/stories/12345
正在显示一个页面,但 Stories_controller.rb 没有 def index
或 def show
更新: 我猜想可能是程序有错误,在这种情况下它将显示应用程序跟踪和 Rails 跟踪。
The first layer is routing and the second layer the controller, so when in View, is there a way to dump out the path or filenames and line numbers of route and controller before reaching view?
I wanted to do this because www.example.com/stories/12345
is showing a page, but stories_controller.rb doesn't have a def index
or def show
Update: I guess it might be as if the program has an error, in which case it will show an application trace and a rails trace.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,除了使用
index
或show
之外没有其他选择,并且它必须在 StoriesController 类中定义。但这并不意味着这些方法是在文件“stories_controller.rb”中定义的。有几个选项:
active_scaffold
,它添加了所有标准 CRUD 操作(索引、显示等)要查看定义方法的位置,您可以在
script/console
会话中键入内容,它将返回一组类/模块,如下所述< a href="https://stackoverflow.com/questions/175655/how-to-find-where-a-ruby-method-is-define-at-runtime">此处。
例如,在我们的 ApplicationController 中,我们包含一个定义方法
login_required
的模块,看起来像这样:希望这会有所帮助。
Well actually there is no other alternative than using a
index
orshow
and it has to be defined inside the class StoriesController. But it does not mean that those methods are defined inside the file "stories_controller.rb".There are a few options:
active_scaffold
that adds all the standard CRUD actions (index, show, ...)To see where a method is defined, you could type inside your
script/console
sessionand it would return a set of classes/modules, as explained here.
For instance, in our ApplicationController we include a module that defines a method
login_required
, and that looks like this:Hope this helps.
我知道这并不能真正回答你的问题,但是......
您可以通过执行以下操作来查看您的路线:
您的 app/views/stories/ 中是否有 show.html.erb ?
I know this doesnt really answer your question, but ...
you can see your routes by doing
do you have show.html.erb in your app/views/stories/ ?