Is my project class is nill or what, can any one explain me this error.
NoMethodError (undefined method
projects' for nil:NilClass):
index'
app/controllers/project_controller.rb:8:inRendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.2ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.4ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (50.0ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.4ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.4ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (41.3ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (93.4ms)
Here is my project controller
before_action :confirm_logged_in
before_action :find_company
def index
@projects = @company.projects.sorted
end
def show
@project = Project.find(params[:id])
end
def new
@project = Project.new()
end
def create
@project = Project.new(project_params)
if @project.save
redirect_to(:action => 'index')
else
render('new')
end
end
def edit
@project = Project.find(params[:id])
end
def update
@project = Project.find(params[:id])
if @project.update_attributes(project_params)
redirect_to(:action => 'index')
else
render('new')
end
end
def delete
@project = Project.find(params[:id])
end
def destory
@project = Project.find(params[:id])
@project.destroy
redirect_to(:action => 'index')
end
private
def project_params
params.require(:project).permit(:name, :position, :type_of_project, :description, :no_of_tasks)
end
def find_company
if params[:company_id]
@company = Company.find(params[:company_id])
end
end
end
So actually what iam doing here is before entering in to projects we need to find the company_id and in index @projects = @company.projects.sorted means that company has many projects.