簡體   English   中英

缺少Ruby on Rails模板

[英]Ruby on Rails template missing

我正在嘗試渲染一個模板下

public/index.html.erb

  def public_index
    @post = Post.all
    render 'public/index'
  end

Missing template public/index

我沒有發現任何問題。 公眾是保留字還是其他?

嘗試使用:

render :file =>  "#{RAILS_ROOT}/public/index.html.erb"

嘗試

render :template => 'public/index'

如果這樣做沒有幫助,請嘗試以下方法

render :edit
render action: :edit
render "edit"
render "edit.html.erb"
render action: "edit"
render action: "edit.html.erb"
render "books/edit"
render "books/edit.html.erb"
render template: "books/edit"
render template: "books/edit.html.erb"
render "/path/to/rails/app/views/books/edit"
render "/path/to/rails/app/views/books/edit.html.erb"
render file: "/path/to/rails/app/views/books/edit"
render file: "/path/to/rails/app/views/books/edit.html.erb"

檢查http://guides.rubyonrails.org/layouts_and_rendering.html

您可以這樣:

將此添加到您的routes.rb文件中。

match '/index', :to => redirect('/index.html')

更新資料

在Rails 4中,應使用“ get”而不是“ match”:

get '/index', :to => redirect('/index.html')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM