Forum: Ruby on Rails Having trouble editing self-reference join model attribute

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
03724bd9cc02f66b731e3917446fcc53?d=identicon&s=25 Anthony Walsh (shinkaku)
on 2007-04-05 06:10
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.

< fields_for "favorite_user", @favs[index] do |favorite_note| %>
  <= favorite_note.text_area :note, "rows" => 5 %>
< end %>

  def favorites
    if request.get?
      @players = Player.find(params[:id]).favorites
      @favs = FavoriteUser.find_all_by_player_id(params[:id])
      self_player = Player.find(params[:id])
      p @params   ##check to see if I got all the notes?

## model
class Player < ActiveRecord::Base
  has_many :favorite_users
  has_many :favorites, :through => :favorite_users

class FavoriteUser < ActiveRecord::Base
  belongs_to :player
  belongs_to :favorite, :foreign_key => "favorite_id", :class_name =>

## 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
This topic is locked and can not be replied to.