programming in Ruby on Rails

Asked

Viewed 49 times

0

I have a form and include a table médicos, and this table has a field enum where you can choose the option of cooperativa, but I have to check on another table of cooperativa if this doctor has a cooperativa.

In the validation, how do I read these two tables and check whether the médico has a cooperativa, because otherwise I have to show a message saying that this doctor does not have cooperativa.

  • you use which database ?

  • yes, I access through active admin.

  • mysql database

  • need to create a Join then, I will put as an answer to exemplify, try playing in mysql and if it works as you want it will help you now

  • private def validate_presence_of_cooperatives errors.add("Cooperative", "There Must Be a Cooperative for this Specialist") if Specialties.Empty? end

  • You need to show the user, in the form, doctors who have no cooperative associate? Because if not, you in the controller would already do something like: @medicos = Medico.com_cooperativa. That way you don’t have to worry about validation. You would only make a Scope in the model of doctor that would return you a collection of doctor that has cooperative

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.