如何为控制器创建 routes.rb 条目?

如何为控制器创建 routes.rb 条目?

问题描述:

我正在尝试用一些 erb 填充 iframe,但我不知道如何创建到新控制器的路由.

I'm trying to populate an iframe with some erb and I can't figure out how to create a route to the new controller.

class TestController < ApplicationController
  def iframe
    load_channels
    render :partial => "report", :layout => "test"
  end
end

这是在我的网页中:

<iframe src="<%= url_for controller: 'test', action: 'iframe' %>" name="report"></iframe>"

我用基本的 html 和 erb 创建了一个布局.

I created a layout with basic html and erb.

我收到没有路由匹配"错误.当我查看 routes.rb 文件时,它是我见过的最令人困惑的配置文件之一.

I'm getting "no route matches" error. When I look at the routes.rb file it's one of the most confusing config files that I've ever seen.

我如何路由到这个控制器?

How do I route to this controller?

你可以试试把 get 'htmlfilename', to:'test#iframe' 放到 routes.rb 里面看看有没有作品.htmlfilename 应该没有扩展名.在 url_for 中,您可以放置​​ path 而不是 controller: 'test', action: 'iframe'.有关更多信息,您可以查看 Rails 此处的路由文档.

You can try to put get ‘htmlfilename’, to:’test#iframe’in the routes.rb and see if it works. The htmlfilename should be without the extension. And in the url_for you can put the path rather than controller: 'test', action: 'iframe'. For more information you can check the Rails routing documentation here.