2016-04-28 103 views
0

我跑進臭名昭着的NoMethodError,即使瀏覽過SO帖子的數量後,我似乎也無法破解。NoMethodError:未定義的方法'客戶端'爲零:NilClass

注:我對CLOUD9開發環境中運行

我正在做的生產力網站,用戶可以有自己的客戶,項目等

我試圖運行clients_display_test.rb測試並且正在接收以下終端錯誤。

任何幫助,將不勝感激,但我會問,如果你決定在我的錯誤是,請指定我缺乏技術理解爲 :)

1) Error: 
ClientsDisplayTestTest#test_profile_display: 
NoMethodError: undefined method `clients' for nil:NilClass 
    app/controllers/clients_controller.rb:4:in `index' 
    test/integration/clients_display_test_test.rb:11:in `block in <class:ClientsDisplayTestTest>' 

48 runs, 127 assertions, 0 failures, 1 errors, 0 skips 

clients_display_test.rb

require 'test_helper' 

class ClientsDisplayTestTest < ActionDispatch::IntegrationTest 
    include ApplicationHelper 

    def setup 
    @user = users(:Robert) 
    end 

    test "profile display" do 
    get '/clients' 
    assert_template "clients/index" 
    assert_select 'title', "Clients" 
    end 
end 

附加的是一些.rb文件,希望可以幫助:

clients_controller.rb

class ClientsController < ApplicationController 

    def index 
     @clients = current_user.clients.paginate(page: params[:page]) 
    end 

    def show 
    end 
end 

的routes.rb

Rails.application.routes.draw do 

    get 'password_resets/newedit' 

    root    'static_pages#home' 
    get 'about' => 'static_pages#about' 
    get 'signup' => 'users#new' 

    get 'login' => 'sessions#new' 
    #the page for new session 
    post 'login' => 'sessions#create' 
    #creates a new session 
    delete 'logout' =>'sessions#destroy' 
    #deletes the session 
    get '/clients' => 'clients#index' 
    get '/clients/show' => 'clients#show' 

    resources :users 
    resources :clients 
    resources :account_activations, only: [:edit] 
    resources :password_resets,  only: [:new, :create, :edit, :update] 
end 

客戶端瀏覽次數:

index.html.erb

<%= provide(:title, 'Clients') %> 

<div class="clients-container container"> 
    <div class="row"> 
     <!-- Add pagination later for multiple folders over multiple pages --> 
    <% if current_user.clients.any? %> 
     <%= render @clients %> 
     <%= will_paginate @clients %> 
    <% end %> 
    </div> 
</div> 

_client.html.erb

<div class="col-md-2 client-folder" style="margin: 10px" id="client - <%= client.id %>"> 
    <span class="clientName" ><%= client.client_name %></span> <br> 
    <span class="contactName"><%= client.contact_name %></span> 
</div> 
+1

您使用的設計? – GoGoCarl

回答

相關問題