首先,我搜索了堆栈溢出并谷歌找出问题,但不幸的是我无法解决问题。
在我将rails 4.2 app升级到5.0之后,就出现了这个问题。
我的应用程序中有一个友谊系统。我可以发送友情请求,但我不能取消它。当我尝试时,rails会抛出错误lockpref("security.tls.version.min", 1);
lockpref("security.tls.version.max", 3);
about:config
以下是友谊模型:
Couldn't find Friendship without an ID
这是友谊控制器:
def self.breakup(user, friend)
transaction do
destroy(find_by_user_id_and_friend_id(user, friend))
destroy(find_by_user_id_and_friend_id(friend, user))
end
end
当我命令+点击class Friendship < ActiveRecord::Base
# ---------------------------------------------------------------------------- #
# -- Associations ------------------------------------------------------------ #
# ---------------------------------------------------------------------------- #
belongs_to :user
belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'
# ---------------------------------------------------------------------------- #
# -- Validation Logic -------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
validates_presence_of :user_id, :friend_id
# ---------------------------------------------------------------------------- #
# -- Connection Logic -------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# -- Create A Friendship Request --------------------------------------------- #
def self.send_request(user, friend)
unless user == friend or Friendship.exists?(user, friend)
transaction do
create(user: user, friend: friend, status: 'pending')
create(user: friend, friend: user, status: 'requested')
end
end
end
# -- Accept Friendship Request ----------------------------------------------- #
def self.accept_request(user, friend)
transaction do
accept_one_side(user, friend)
accept_one_side(friend, user)
end
end
# -- Decline Friendship Request, Disconnect or Cancel Pending Request -------- #
def self.breakup(user, friend)
transaction do
destroy(find_by_user_id_and_friend_id(user, friend))
destroy(find_by_user_id_and_friend_id(friend, user))
end
end
# -- Return True If The Users Are (Possibly Pending) Friends ----------------- #
def self.exists?(user, friend)
not find_by_user_id_and_friend_id(user, friend).nil?
end
# -- Update The DB With One Side of An Accepted Friendship Request ----------- #
private
def self.accept_one_side(user, friend)
request = find_by_user_id_and_friend_id(user, friend)
request.status = 'accepted'
request.save!
end
end
时,RubyMine将我带到这里:
class FriendshipsController < ApplicationController
before_filter :setup_friends
def connect
Friendship.send_request(@user, @friend)
redirect_to request.referrer
end
def accept
if @user.requested_friends.include?(@friend)
Friendship.accept_request(@user, @friend)
end
redirect_to request.referrer
end
def cancel
if @user.pending_friends.include?(@friend)
Friendship.breakup(@user, @friend)
end
redirect_to request.referrer
end
def decline
if @user.requested_friends.include?(@friend)
Friendship.breakup(@user, @friend)
end
redirect_to request.referrer
end
def disconnect
if @user.friends.include?(@friend)
Friendship.breakup(@user, @friend)
end
redirect_to request.referrer
end
private
def setup_friends
@user = User.find(current_user.id)
@friend = User.find(params[:id])
end
end