代码之家  ›  专栏  ›  技术社区  ›  Junaid Farooq

如何为没有application.erb rails的控制器使用单独的erb文件

  •  0
  • Junaid Farooq  · 技术社区  · 6 年前

    我想用不同的 .erb 文件而不是默认值 application.erb ,我按照它在 https://guides.rubyonrails.org/layouts_and_rendering.html#finding-layouts

    我在routes.rb中创建了一条路线

    get "/vue/v1/" => "vue#vue"
    

    控制器作为 vue_controller.rb 它的内容是

    class VueController < ApplicationController
      layout "vue"
      def vue
      end
    end
    

    在我的 view/layouts/ ,我还创建了一个文件作为 vue.html.erb 以便控制器可以使用它。内容 Vu.HTML.Erb 一样简单 <%= javascript_pack_tag 'application' %> 但是每当我去 "/vue/v1/" 它只给了我错误

    VueController#vue is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: [] NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Abdul Baig    6 年前

    你做错的是你的控制器,你没有你的视图 vue 行动。尝试在您的 views/vue