Rails best practice for setting not accesible attributes in model -


I am a newbie for rail, and I have a good solution to keep in my model safe before saving it I was thinking in, but I can not find a proper way of doing it

Let's say that I have users who are companies, and these companies can have many customers by saving a new customer First, I want to set my company_id, etc. Areas receiving Kanpani_aid of Chalu_usr which is stored in the session (I'm using Divijh).

I was thinking about using a model callback, as it was before or before, but then I realized that the passport model tests I could have failed, because when they were turned on There will be no current user ...

Is this the best practice to set this parameter, which is to set up automatically?

Thank you in advance!

Just set in the controller. def make @new_user = User.new (params [: user]) @ new_user.company = current_user.company # & lt; If here you are setting it in model callback, then there are some disadvantages if @new_user.save # ... else # ...

here.

  • This breaks your tests
  • This is not needed everywhere - you create an admin frontend.

Comments