Anthony Walsh
2007-Apr-05 04:10 UTC
Having trouble editing self-reference join model attribute
I''m a newbie in rails and working on my first project with it. I have a database that uses a self reference through a join model to add favorite players. In the join model I have an additional attribute for players to make notes of each favorite player. My problem is I''m having difficulty editing the note attribute. All the favorite players are displayed all at once along with their notes. I do this by using fields_for, but I can only capture the first note of the page when I post. ##view < fields_for "favorite_user", @favs[index] do |favorite_note| %> <= favorite_note.text_area :note, "rows" => 5 %> < end %> ##controler def favorites if request.get? @players = Player.find(params[:id]).favorites @favs = FavoriteUser.find_all_by_player_id(params[:id]) elsif request.post? self_player = Player.find(params[:id]) p @params ##check to see if I got all the notes? end end ## model class Player < ActiveRecord::Base has_many :favorite_users has_many :favorites, :through => :favorite_users end class FavoriteUser < ActiveRecord::Base belongs_to :player belongs_to :favorite, :foreign_key => "favorite_id", :class_name => "Player" end ## database tables CREATE TABLE `players` ( `id` int(11) NOT NULL auto_increment, `username` varchar(50) NOT NULL, PRIMARY KEY (`id`) ); CREATE TABLE `favorite_users` ( `player_id` int(11) default NULL, `favorite_id` int(11) default NULL, `note` varchar(100) default NULL ); -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---