我正在使用Rails 4構建社交網絡課程4 & Devise。Rails 4 - 未定義的方法'認證'爲零:NilClass
我堅持試圖讓一門課程來傳遞,這是我得到的錯誤:
1) Error:
UserFriendshipsControllerTest#test_: #new when not logged in should get redirected to the login page. :
NoMethodError: undefined method `authenticate!' for nil:NilClass
test/controllers/user_friendships_controller_test.rb:8:in `block (3 levels) in <class:UserFriendshipsControllerTest>'
這是我users_friendships_controller_test.rb:
require 'test_helper'
class UserFriendshipsControllerTest < ActionController::TestCase
context "#new" do
context "when not logged in" do
should "get redirected to the login page" do
get :new
assert_response :redirect
end
end
end
end
我user_friendship.rb :
class UserFriendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: "User", foreign_key: "friend_id"
private
def friendship_params
params.require(:user).permit(:user_id, :friend_id, :friend)
end
end
我已經添加到我的user_friendships_controller.rb的唯一事情是一個空白的新方法和:
before_filter :authenticate_user!, only: [:new]
請讓我知道我是否應該發佈任何更多的代碼。
謝謝
你能提供'user_friendships_controller'上市 –
@farhatmihalko '類UserFriendshipsController
mycellius