1
votes

I am new to rails and I am facing this error whenever I try to reload the server page and actually I tried almost all the provided solutions for this problem asked by other people and nothing helped

Missing template home/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/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: I am not using haml and I also tried rendering nothing inside it

All what I did in my app is just implementing devise and adding these things to my

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>

and here is it my routes.rb

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

and finally my home_controller

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

1 Answers

2
votes

When you hit an action in Rails, in your case index action, it automatically render its template with templates name matching the name of its action. In your case when you send a request to index action of home controller, user is not signed in so rails is looking for a template views/home/index.html.erb, but you don't have that template there, causing your error.

For details on how things work in rails, checkout rail guides