[Rails] Create several models at once and validating

Eduardo Yáñez Parareda eduardo.yanez at gmail.com
Wed Aug 16 11:46:02 GMT 2006


I have two models User and Team. Also I have a register form where the 
new
user fill in her data and choose a name for a Team.

Well, in the user model there are several validations which work fine, 
but
team model also have a validation for a uniqueness name that doesn't 
fire up
when she gives an existent team's name.

This is the flow it follows:

/user/new -> it shows a form to fill user's data and a team's name -> 
Create ->
UserController
  def create
    @user = User.create(params)
    if request.post? and @user.save
     ......
    end
  end

User
  validates_uniqueness_of :username <--- THIS WORKS FINE
  def self.create
    user = User.new(params[:user])
    team = Team.new(params[:team])
    user.team = team
    user
  end

Team
  validates_uniqueness_of :name <--- THIS DOESN'T WORK

What am I doing wrong?

-- 
Posted via http://www.ruby-forum.com/.


More information about the Rails mailing list