Rails 4.1 无法在控制器中执行@user_friendship.save 并且returns 出错
Rails 4.1 can't do the @user_friendship.save in the controller and returns an error
你好显然无法保存我在 rails 4.1 中的工作添加状态机 gem 并做了一些更多的细节,比如当你在朋友中添加某人时,我的控制器出现错误 @ user_friendship.save
这是控制器线
我在我的 User_Friendships 控制器中遇到此错误,并且包含 @user_friendship.save 的行每次都失败
def create
if params[:user_friendship] && params[:user_friendship].has_key?(:friend_id)
@friend = User.where(profile_name: params[:user_friendship][:friend_id]).first
@user_friendship = current_user.user_friendships.new(friend: @friend)
@user_friendship.save
flash[:success] = "You are now friends with #{@friend.full_name}"
redirect_to profile_path(@friend)
else
flash[:error] = "Friend required"
redirect_to root_path
end
end
这是我添加用户好友时出现的错误
NoMethodError in UserFriendshipsController#create
protected method `around_validation' called for #<StateMachine::Machine:0x007fe631d43a68>
{"utf8"=>"✓",
"authenticity_token"=>"gPaCH/833buhbi53USaprtbmvFGjNCHE7RYY+DW071s=",
"user_friendship"=>{"friend_id"=>"popo"},
"commit"=>"Yes,
Add friend"}
我是 rails 的新人,请您解释更多,以便我理解为什么会这样,谢谢!
你用的是最新版本的statemachine吗?如果不是,请尝试最新版本的状态机。
https://github.com/pluginaweek/state_machine/issues/295
应用这个补丁,直到他们修复它,它才会起作用
config/initializers/state_machine_patch.rb
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
end
end
你好显然无法保存我在 rails 4.1 中的工作添加状态机 gem 并做了一些更多的细节,比如当你在朋友中添加某人时,我的控制器出现错误 @ user_friendship.save
这是控制器线 我在我的 User_Friendships 控制器中遇到此错误,并且包含 @user_friendship.save 的行每次都失败
def create
if params[:user_friendship] && params[:user_friendship].has_key?(:friend_id)
@friend = User.where(profile_name: params[:user_friendship][:friend_id]).first
@user_friendship = current_user.user_friendships.new(friend: @friend)
@user_friendship.save
flash[:success] = "You are now friends with #{@friend.full_name}"
redirect_to profile_path(@friend)
else
flash[:error] = "Friend required"
redirect_to root_path
end
end
这是我添加用户好友时出现的错误
NoMethodError in UserFriendshipsController#create
protected method `around_validation' called for #<StateMachine::Machine:0x007fe631d43a68>
{"utf8"=>"✓",
"authenticity_token"=>"gPaCH/833buhbi53USaprtbmvFGjNCHE7RYY+DW071s=",
"user_friendship"=>{"friend_id"=>"popo"},
"commit"=>"Yes,
Add friend"}
我是 rails 的新人,请您解释更多,以便我理解为什么会这样,谢谢!
你用的是最新版本的statemachine吗?如果不是,请尝试最新版本的状态机。 https://github.com/pluginaweek/state_machine/issues/295
应用这个补丁,直到他们修复它,它才会起作用
config/initializers/state_machine_patch.rb
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
end
end