How do I create a routes.rb entry for a controller?

冷暖自知 提交于 2019-12-13 04:05:19

问题


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

This is in my webpage:

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

I created a layout with basic html and erb.

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?


回答1:


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.



来源:https://stackoverflow.com/questions/54209837/how-do-i-create-a-routes-rb-entry-for-a-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!