On 21 July 2011 20:53, Leonel *.* <li...@ruby-forum.com> wrote: > I know in the model we can add validations. But how about if I need > different validations depending on the controller. > > For example... > 1) if the User is being created from the accounts controller, I want to > REQUIRE the username be entered. > 2) if the User is being created from the users controller, I want to NOT > REQUIRE the username. > > validates_presence_of :username, :on => :create requires the username > 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. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.