jeudi 23 août 2018

Ruyb on Rails DB entry in a model (RoR 3)

There is:

  • Project (has_many :group_permissions)
  • GroupPermission (belongs_to :project)

I have a form where you can create a new project. A project has several attributes like name, status etc. and now important: iit. iit is selectable with radio buttons: yes or no.

What I want:

If someone selects yes on iit in the Project form, there should be a new record in GroupPermission. So in EVERY project where iit= 1 there should be a certain GroupPermisson.

Can I make / check this in the GroupPermission model? Like if

class GroupPermission < ActiveRecord::Base
    if Project.where(iit: 1)
     make me a record for each project

end

Can I even make database entries in the model like so?

Is this the right way?

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire