ruby on rails - How to prevent automatic rollback when trying to set user as admin -
hi active admin installed on app; trying set new user admin using rails console. selecting specific user in table user. writting
user.admin = true then
user.save but
(0.2ms) begin (0.3ms) rollback => false i have automatic rollback... doing wrong ? here's user model
class user < activerecord::base after_create :send_welcome_email # include default devise modules. others available are: # :confirmable, :lockable, :timeoutable , :omniauthable include algoliasearch algoliasearch index_name: "user#{env['algolia_suffix']}" attribute :email, :licence_number, :ranking, :first_name, :last_name attributestoindex ['email', 'licence_number', 'ranking','first_name', 'last_name'] end extend enumerize enumerize :genre, in: [:male, :female] enumerize :ranking, in: ['nc', '30/5', '30/4', '30/3', '30/2', '30/1', '30', '15/5', '15/4', '15/3', '15/2', '15/1', '15', '5/6', '4/6', '3/6', '2/6', '1/6', '0', '-2/6', '-4/6', '-15', '-30'] 23 devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [ :facebook ] has_many :subscriptions, dependent: :destroy has_many :tournaments, dependent: :destroy has_attached_file :picture, styles: { medium: "300x300>", thumb: "100x100>" } validates_attachment_content_type :picture, content_type: /\aimage\/.*\z/ has_attached_file :licencepicture, styles: { medium: "300x300>", thumb: "100x100>" } validates_attachment_content_type :licencepicture, content_type: /\aimage\/.*\z/ has_attached_file :certifmedpicture, styles: { medium: "300x300>", thumb: "100x100>" } validates_attachment_content_type :certifmedpicture, content_type: /\aimage\/.*\z/ validates :first_name, presence: { message: 'veuillez remplir votre prénom' }, on: :update validates :last_name, presence: { message: 'veuillez remplir votre nom' }, on: :update validates :iban, format: { with: /\a[a-za-z]{2}\d{2}\s*(\w{4}\s*){2,7}\w{1,4}\s*\z/, message: 'le format de votre iban doit être du type fr70 3000 2005 5000 0015 7845 z02' }, on: :update validates :bic, format: { with: /([a-za-z]{4}[a-za-z]{2}[a-za-z0-9]{2}([a-za-z0-9]{3})?)/, message: 'le format de votre bic doit être du type axabfrpp ' }, :allow_blank => true, on: :update validates :telephone, format:{ with: /\a(\+33)[1-9]([-. ]?[0-9]{2}){4}\z/, message: 'le format de votre numéro doit être du type +33602385414' }, :allow_blank => true, on: :update has_many :messages has_many :notifications def self.find_for_facebook_oauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_create |user| user.provider = auth.provider user.uid = auth.uid user.email = auth.info.email user.password = devise.friendly_token[0,20] user.first_name = auth.info.first_name user.last_name = auth.info.last_name user.picture = auth.info.image user.token = auth.credentials.token user.token_expiry = time.at(auth.credentials.expires_at) end end # def initialize # @errors = activemodel::errors.new(self) # end def age = time.now.utc.to_date now.year - birthdate.year - (birthdate.to_date.change(:year => now.year) > ? 1 : 0) end def full_name if last_name != nil && first_name.nil? "#{last_name.capitalize}" elsif first_name != nil && last_name.nil? "#{first_name.capitalize}" elsif last_name.nil? && first_name.nil? "" else "#{first_name.capitalize} #{last_name.capitalize}" end end def create_mangopay_natural_user_and_wallet natural_user = mangopay::naturaluser.create(self.mangopay_user_attributes) wallet = mangopay::wallet.create({ owners: [natural_user["id"]], description: "my first wallet", currency: "eur", }) kyc_document = mangopay::kycdocument.create(natural_user["id"],{type: "identity_proof", tag: "driving licence"}) self.mangopay_natural_user_id= natural_user["id"] self.wallet_id = wallet["id"] self.kyc_document_id = kyc_document["id"] self.save end def mangopay_user_attributes { 'email' => self.email, 'firstname' => self.first_name, 'lastname' => self.last_name, # todo: change this! add 2 columns on users table. 'birthday' => self.date_of_birth.to_i, # todo: change this! add 1 column on users table 'nationality' => 'fr', # todo: change this! 'countryofresidence' => 'fr' # todo: change this! } end private def send_welcome_email usermailer.welcome(self).deliver end end
since validation issue, take @ the guide. errors:
user.errors.full_messages
Comments
Post a Comment