akm
akm

Reputation: 65

How to render views correctly on rake?

view = ActionView::Base.new(ActionController::Base.view_paths, {}, ActionController::Base.new)

# works fine
puts view.render(file: 'books/index')

# doesn't work
puts view.render('books/index', layout: 'application')                                                                                                      

ActionView::MissingTemplate: Missing partial books/_index with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:

And it doesn't work when there is user_signed_in? in view (view.render(file: 'books/index')).

ActionView::Template::Error: undefined method `user_signed_in?' for #

Upvotes: 0

Views: 92

Answers (2)

coderVishal
coderVishal

Reputation: 9109

You have not added a partial, _index.html.erb in your app/views/books

Upvotes: 0

Puja
Puja

Reputation: 601

I think you need to create _index.html.erb (partial file) in app/view/books folder.

Upvotes: 0

Related Questions