【问题标题】:Missing template Error in rubyruby 中缺少模板错误
【发布时间】:2015-06-25 04:04:41
【问题描述】:

我是 Rails 新手,每当我尝试重新加载服务器页面时都会遇到此错误,实际上我尝试了几乎所有针对其他人提出的问题提供的解决方案,但没有任何帮助

缺少带有 {:locale=>[:en]、:formats=>[:html]、:variants=>[]、:handlers=>[:erb] 的模板主页/索引、应用程序/索引、 :builder, :raw, :ruby, :coffee, :jbuilder]}。搜索:* “/Users/Bassem/Qulb/app/views”* “/Library/Ruby/Gems/2.0.0/gems/twitter-bootstrap-rails-3.2.0/app/views” * "/Library/Ruby/Gems/2.0.0/gems/devise-3.5.1/app/views"

ps:我没有使用 haml,我也尝试在其中不渲染任何内容

我在我的应用中所做的只是实现设计并将这些东西添加到我的

application.html

<!DOCTYPE html>
<html>
<head>
  <title>Qulb</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

  <!-- Optional theme -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">

  <!-- Latest compiled and minified JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>



</head>
<body>

  <div class="container">
    <nav class="navbar navbar-default">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-3" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Home</a>
        </div>
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-3">
          <button type="button" class="btn btn-default navbar-btn">Sign in</button>
        </div>
      </div>
    </nav>



  <%= yield %>

  </div>




</body>
</html>

这是我的 routes.rb

Rails.application.routes.draw do
  resources :books
  devise_for :users
  root 'home#index'
end

最后是我的 home_controller

class HomeController < ApplicationController
  def index
    redirect_to books_path if user_signed_in?
end
end

【问题讨论】:

    标签: ruby-on-rails ruby twitter-bootstrap ruby-on-rails-4


    【解决方案1】:

    当您在 Rails 中点击一个动作时,在您的案例索引动作中,它会自动使用与其动作名称匹配的模板名称来呈现其模板。在您的情况下,当您向家庭控制器的 index 操作发送请求时,用户未登录,因此 rails 正在寻找模板 views/home/index.html.erb ,但你没有那个模板,导致你的错误。

    有关 Rails 中的工作原理的详细信息,请查看rail guides

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-20
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多