has and belongs to many - Adding an object in a has_and_belongs_to_many association with Rails -


i have simple has_and_belongs_to_many association between users, works perfectly.

however, add friendship relation between new users created , first user (yup, myspace's tom), directly in create method:

def create   @user = user.new(params[:user])   if @user.save     @user.friends << user.find(1)     redirect_to root_path   else     render :action => :new   end end 

i don't understand why doesn't work. no error, nothing, doesn't add first user new user's friends.

(for information, i'm using rails 2.3.4)

what should do?

kevin

first, fire script/console , check whether associations working correctly in console. second, must arrange code association between user , friends before save command.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -