如何在rake上正确渲染视图?

时间:2015-08-06 04:15:13

标签: ruby-on-rails

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:缺少部分图书/ _index与{: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]}。搜索:

当视图user_signed_in?中有view.render(file: 'books/index')时,它无效。

  

ActionView :: Template ::错误:未定义的方法`user_signed_in?'对于#

2 个答案:

答案 0 :(得分:0)

我认为您需要在app / view / books文件夹中创建_index.html.erb(部分文件)。

答案 1 :(得分:0)

您尚未在app / views / books中添加部分_index.html.erb