Rendering problems (ActionView :: MissingTemplate ... Error) in a custom plugin

I am trying to develop a plugin for Ruby on Rails and have run into problems rendering my html view. My directory structure looks like this:

File structure

---/vendor
      |---/plugins
             |---/todo
                     |---/lib
                            |---/app
                                    |---/controllers
                                            |---todos_controller.rb
                                    |---/models
                                            |---todos.rb
                                    |---/views
                                            |---index.html.erb
                             |---todo_lib.rb
                     |---/rails
                             |---init.rb

In /rails/init.rb

require 'todo_lib'

In / lib / app / todo _lib.rb

%w{ models controllers views }.each do |dir|
  # Include the paths:
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/lib/app/models
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/lib/app/controllers
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/lib/app/views
  path = File.expand_path(File.join(File.dirname(__FILE__), 'app', dir))
  # We add the above path to be included when Rails boots up
  $LOAD_PATH << path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)
end

In todo / lib / app / controller / todos_controller.rb

class TodosController < ActionController::Base
  def index
  end
end

In todo / lib / app / views / index.html.erb

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
  <title>Todos:</title>
</head>
<body>
<p style="color: green" id="flash_notice"><%= flash[:notice] %></p>
<h1>Listing Todos</h1>
</body>
</html>

In /myRailsApp/config/routes.rb

ActionController::Routing::Routes.draw do |map|
  # The priority is based upon order of creation: first created -> highest priority.

  map.resources :todos
  ...

The error I am getting is the following:

Missing template

Missing todos / index.erb template in view / views of view path

Can someone give me a hand and tell me what I'm doing wrong here, which leads to the index.html.erb file not showing up? Really appreciate!


EDIT:

I have already tried the following without success:

In / todo / lib / app / controllers / todos _controller.rb

def index
   respond_to do |format|
      format.html # index.html.erb
    end
end

EDIT:

hakunin . .

, Rails ( , ), , :

---/vendor
      |---/plugins
             |---/todo
                     |---/lib
                     |---/app
                            |---/controllers
                                    |---todos_controller.rb
                            |---/models
                                    |---todos.rb
                            |---/views
                                    |---/todos
                                            |---index.html.erb
                            |---todo_lib.rb
                     |---/rails
                            |---init.rb

:

todo/lib/todo_lib.rb

%w{ models controllers views }.each do |dir|
  # Include the paths:
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/app/models
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/app/controllers
  # /Users/Me/Sites/myRailsApp/vendor/plugins/todo/app/views
  path = File.expand_path(File.join(File.dirname(__FILE__), '../app', dir))
  # We add the above path to be included when Rails boots up
  $LOAD_PATH << path
  ActiveSupport::Dependencies.load_paths << path
  ActiveSupport::Dependencies.load_once_paths.delete(path)
end

: path = File.expand_path (File.join(File.dirname(FILE), '../app', )). [ "", ].

script/server index.html.erb todo/app/views/todos.

+3
1

, "engine". "app" "config" ( /lib ). // , Rails. config/routes.rb , .

. http://github.com/neerajdotname/admin_data , .

+1

Source: https://habr.com/ru/post/1724883/


All Articles