Tuler
Tuler

Reputation: 19

Ruby on Rails template missing

I am trying to render a templated under

public/index.html.erb

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

Missing template public/index

I don't see anything wrong with it. Is public a reserved word or something?

Upvotes: 0

Views: 204

Answers (3)

Mayur Shah
Mayur Shah

Reputation: 3449

You can do like this:

Add this, into your routes.rb file.

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

Update

In Rails 4, it should use "get", not "match":

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

Upvotes: 0

ashvin
ashvin

Reputation: 2040

Try

render :template => 'public/index'

If this will not help then try following ways

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"

Check http://guides.rubyonrails.org/layouts_and_rendering.html

Upvotes: 0

Shannon
Shannon

Reputation: 3018

Try using:

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

Upvotes: 1

Related Questions