EastsideDev
EastsideDev

Reputation: 6639

Missing template issue, rendering a non-default view

Rails 5.2

I have a books_controller.rb, and from one of the methods, I am trying to render a view from another model

In my controllers/books_controller.rb, I have:

def author_reviews
  .....
  render "authors/index"
end

and I have a

views/authors/_index.html.slim (note the underscore)

There's a button on a view, that when I click, it calls the method author_reviews, in the books_controller.rb.

However, when I click it, I get the message:

Missing template authors/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby, :slim, :coffee, :jbuilder]}. Searched in: * "/app/views" * "/Users/xxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/devise-4.7.1/app/views" * "/Users/xxx/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/kaminari-core-1.1.1/app/views"

So, it does not look like it's checking views/authors/ for the _index.html.slim template.

Any ideas?

Upvotes: 0

Views: 25

Answers (1)

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

Try passing template option, change name of the view from _index to index and then

render template: 'authors/index', locals: { ... }

Give it a try!

Upvotes: 1

Related Questions