regardless of the controller being used.
Just to make sure I understand the requirement, you want to be able to
create a user record in the database with an empty user name if it is
being created in the users controller? It seems a bit odd to have a
user record in the database with no username.
Sorry, I should’ve explained more. This is the general idea.
There is a Sign Up form which creates 3 records in 3 different models:
Account
Company (belongs to account)
User (belongs to user)
So the Sign Up form, creates the user from the accounts_controller.rb @account = Account.new
company = @account.companies.build
company.users.build
Now, once the sign up is complete, the user can invite other people to
user the web app. So he adds users, the app sends an invitation email
and when the person clicks on the invitation email, it gives it a form
to choose desired username.
In summary…
when the user is being created from the accounts controller (sign
up), REQUIRE username
when the user is adding other users from users controller (add user),
DO NOT REQUIRE username
I don’t think you want to think of this as a controller based thing.
Apart from anything else, if you at some later point want to update a
user object then you’ll need to know what validations to apply.
Instead, you could have a state column, and apply validations based on
that state. When the accounts controller creates a user, it sets its
state to (for example) signed_up, and that state requires all your
validation, whereas in the second case the controller could set the
state to ‘invited’, which has a separate set of validations. (if you
do go down this route, the aasm gem can help you manage states and the
transitions between them)
Instead, you could have a state column, and apply validations based on
that state. When the accounts controller creates a user, it sets its
state to (for example) signed_up, and that state requires all your
validation, whereas in the second case the controller could set the
state to ‘invited’, which has a separate set of validations. (if you
do go down this route, the aasm gem can help you manage states and the
transitions between them)
Ok, let’s say I do add a state column. How would I setup the validation,
you mean, in the model check the state and apply validation according to
the state?
Would you recommend I set the state column…
as string or
as a foreign key to a states tables that lists the states?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.