无法使用我的控制器显示我的html创建的视图

时间:2017-07-01 23:58:23

标签: ruby-on-rails ruby

我对rails非常陌生并且有一个问题。

我想指示我的控制器指向我创建的html.erb视图。

我尝试了各种版本:

def index
  render :"viewName"
end

def index
  render :viewName
end

def index
  render : "viewName.html.erb"
end

我的路由器设置如下:

Rails.application.routes.draw do
  root 'application#index'
end

2 个答案:

答案 0 :(得分:1)

您只需按照约定,如果您将其指向controller: Applicationaction: Index,那么您需要一个"应用程序"视图中的文件夹,以及" index.html.erb"在此应用程序文件夹中,您不需要在操作中调用任何渲染。

因此,在这种情况下,请创建以下文件夹

/app/views/application

在里面放置你的:

index.html.erb

在你的application_controller.rb

def index; end

我不会使用应用程序控制器......

答案 1 :(得分:0)

如果你想渲染部分

render partial: 'some_view'

render 'some_view'

这将查找文件_some_view.html.erb

如果你想渲染一些模板,那么

render template: 'template_name'

这将寻找template_name.html.erb