Advanced ruby ​​on rail models and validation

In general, I have a website that needs to have a complicated registration process. And in this registration process I need to include 4 tables from the database.

Now ... I cannot check the model one by one and enter 4 of them into the database. Is there a way to make common points of all these tables in one model?

Say: A model Userhas columns: username, nameetc. PackageThe model has: type, account_number etc.

And during the registration process I need to specify the username, name, account_number and check them. How to do it?

+4
source share
3 answers

Not seeing your model structure, this is just an assumption, but here goes:

-

Virtual attributes

User attr_accessor virtual attributes - , setter / getter User.

, , , :

#app/models/user.rb
Class User < ActiveRecord::Base
    attr_accessor :new, :values, :to, :validate
    validates, :new, :values, :to, :validate, presence: true
end

User - ,


attr_accessor

, , Rails - modules classes.

, model - class, getter/setter. ActiveRecord @user.attribute

, attr_accessor, User, , , ,

+2

, . 4 , . :

  • User
  • create 4 different forms (for example, applies to the ActiveModeluser or gem reform)
  • add confirmation for each form
  • after form.valid?save part of the user information in @userobject

That's all.

+1
source

Source: https://habr.com/ru/post/1544434/


All Articles