Я обновил Ruby и Rails версия моего проекта.
Ruby 2.2.3
-> 2.5.1
Rails 4.1.8
-> 5.1.7
Когда я пытаюсь зарегистрировать нового пользователя, я получаю сообщение об ошибке:
ArgumentError (wrong number of arguments (given 2, expected 0..1)):
app/controllers/users/registrations_controller.rb:41:in `create'
Это происходит как со стороны клиента (веб-интерфейс), так и со стороны Rails console.
registrations_controller.rb:
39: def create
40: build_resource(sign_up_params)
41: resource_saved = resource.save
42:
43: yield resource if block_given?
44:
45: if resource_saved
46: if resource.active_for_authentication?
...
В консоли Rails:
user = User.new(email: "qwe@test.com", name: "qwe qwe", password: '123123123')
=> #<User id: nil, email: "qwe32@q.com", created_at: nil...
user.save!
ROLLBACK
Traceback (most recent call last):
1: from (irb):4
ArgumentError (wrong number of arguments (given 2, expected 0..1))
Пользователь модель:
class User < ActiveRecord::Base
extend FriendlyId
include InstantSearch
include PushNotificationToFollowers
include CarrierWave::MiniMagick
serialize :site_link, Array
serialize :followers_ids, Array
acts_as_token_authenticatable
acts_as_follower
acts_as_followable
acts_as_liker
acts_as_likeable
attr_accessor :site_link_raw
mount_uploader :avatar, AvatarUploader
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable,
omniauth_providers: [:facebook, :google_oauth2]
validates :name, presence: true
validates :slug, uniqueness: true
validates_format_of :slug, with: /\A\d+[a-zA-Z]+\S*\z|\A[^\s\d]\S*\z/i, message: 'minimum one letter, without spaces', on: :update
friendly_id :slug_candidates, use: [:slugged, :finders]
{some associations}
before_create :check_slug
after_create :set_membership
after_create :send_welcome_email
after_create :set_settings
ransacker :id,
formatter: ->(bool) {
users_ids = SoundUploader.select(:user_id).where(active:true)
if bool == 'true'
users_ids.present? ? where("users.id IN (#{users_ids.to_sql})").map(&:id) : nil
else
where("users.id NOT IN (#{users_ids.to_sql})").map(&:id)
end
} do |user|
user.table[:id]
end
def check_slug
unless self.slug.match(/\A\d+[a-zA-Z]+\S*\z|\A[^\s\d]\S*\z/i)
new_slug = "project-#{self.slug}"
user = User.find_by(slug: new_slug)
new_slug = "#{new_slug}-#{DateTime.current.to_i}" if user
self.slug = new_slug
end
end
def set_membership
self.memberships.create
end
def send_welcome_email
UserMailer.welcome_email(self.id).deliver
end
def set_settings
self.create_setting
end
С другими моделями я не получаю эту ошибку.
Но с Пользовательская модель, независимо от того, как я звоню save
метод, эта ошибка всегда появляется.