NoMethodError(未定義的方法projects' for nil:NilClass): app/controllers/project_controller.rb:8:in
索引」NoMethodError(未定義的方法`項目的零:NilClass):
Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_source.erb (21.7ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.2ms) 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 (3.6ms) 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 (89.7ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (0.6ms) 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.6ms) 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.7ms) 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.5ms) 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 (51.7ms) 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 (1.2ms) 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.9ms) Rendered /Users/ajaysithagari/.rvm/gems/ruby-2.2.1/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (116.8ms)
這裏是一個項目的控制器:
class ProjectController < ApplicationController
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()
@project_count = Project.count + 1
@companys = Company.order("position ASC")
end
def create
@project = Project.new(project_params)
if @project.save
redirect_to(:action => 'index')
else
@project_count = Project.count + 1
@companys = Company.order("position ASC")
render('new')
end
end
def edit
@project = Project.find(params[:id])
@project_count = Project.count
@companys = Company.order("position ASC")
end
def update
@project = Project.find(params[:id])
if @project.update_attributes(project_params)
redirect_to(:action => 'index')
else
@project_count = Project.count
@companys = Company.order("position ASC")
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