次のアクションは、新しいコメントを作成します。
- ユーザーには多くのステータスがあります
- ステータスには多くのコメントがあります
head 401 and return
何度も繰り返されないように、このアクションを最適化するにはどうすればよいですか。
def create
@user = User.where(id: params[:user_id]).first
if @user
if current_user.friend_with?(@user) or current_user == @user
@status = @user.statuses.where(id: params[:status_id]).first
if @status
@comment = @status.comments.build(params[:comment])
@comment.owner = current_user
if @comment.valid?
@comment.save
current_user.create_activity(:comment_status, @comment, @user)
else
head 401 and return
end
else
head 401 and return
end
else
head 401 and return
end
else
head 401 and return
end
end
ありがとうございました。