【问题标题】:How to render views correctly on rake?如何在 rake 上正确渲染视图?
【发布时间】:2015-10-29 01:39:37
【问题描述】:
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:缺少带有 {: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::Error: 未定义方法 `user_signed_in?' #

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 我没有添加部分 _index.html.erb,因为我没有在任何地方调用 _index.html.erb。
      猜你喜欢
      • 2013-06-30
      • 2012-06-30
      • 2021-02-10
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-18
      相关资源
      最近更新 更多