I
I
Ismail2020-04-20 14:37:42
Ruby on Rails
Ismail, 2020-04-20 14:37:42

String generation without using callback?

Good time of the day. I want to generate a line without using callbacks in the model.
I decided to create, for example, a link directly in the controller, in the new method:

Method
def create
      @user = User.new(link: SecureRandom.urlsafe_base64[0..9])

      if @user.save

        render json: @user, status: :created
      else
        render json: { errors: @user.errors }, status: :unprocessable_entity
      end
    end

But when it gives out that , because this very link is validated in the model. At the same time, it is quite possible to do this in the rails console. How can you do this without using callbacks ? Thank you in advance. rails db:resetlink can't be blank



Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Bordenyuk, 2020-04-20
@gosugod

db:resetremoves all tables from the database, creates them according to the schema and starts the seeds.
I propose to see what is happening in the seeds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question