I'm learning Ruby on Rails and as part of practise I'm building a Bug Tracker System, which has a Manager, Developer and QA.
I want to display all the projects the Manager has created on his Home Screen. These proejcts are present in a table projects.
In my manager_controller, I have this code:
class ManagerController < ApplicationController
def index
@projects = Project.all
end
def create
end
end
And this is my index.html.erb in views/manager:
<div class="container">
<h1>Manager's Feed</h1>
<p>Hello <%=current_user.username%></p>
<%= link_to "Create Project", new_project_path, :class => "btn btn-success"%>
<table id='employee-table' class="table table-hover">
<thead class="thead-light">
<tr>
<th>ID</th>
<th>Title</th>
<th colspan="2"></th>
</tr>
</thead>
<tbody>
<% @projects.each do |project| %>
<tr>
<td><%= project.id %></td>
<td><%= project.title %></td>
</tr>
<% end %>
</tbody>
</table>
<div>
<%= link_to "Logout", destroy_user_session_path, :method => :delete %>
</div>
</div>
But this is giving me following error:
I'm unable to see why @projects is Null as I had defined it in my controller. Can anyone help me in fixing this problem?
Update 1 My routes.rb file:
Rails.application.routes.draw do
get 'project/show'
resources 'project'
resources 'manager'
resources 'developer'
resources 'qa'
devise_for :users
get 'home/index'
root to: "home#index"
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
HomeController:
class HomeController < ApplicationController
before_action :authenticate_user!
def index
@projects = Project.all
if current_user.manager?
render '../views/manager/index.html.erb'
end
if current_user.developer?
render '../views/developer/index.html.erb'
end
if current_user.quality_assurance?
render '../views/qa/index.html.erb'
end
end
end

