On Wed, Apr 21, 2010 at 8:08 AM, Veena Jose <[email protected]> wrote:
>
> Hai friends,
> I hav two models related with habtm
>
> class User < ActiveRecord::Base
> has_and_belongs_to_many :station,
> :join_table => "stations_users",
> :foreign_key => "user_id",
> :association_foreign_key => "station_id"
Shouldn't this be
has_and_belongs_to_many :stations
The plurality is important. Also with that change the join_table,
foreign_key and association_foreign key options are unnecessary since
those are the defaults.
>
> class Station < ActiveRecord::Base
> has_and_belongs_to_many :user
And this should be
has_and_belongs_to_many :users
> end
>
> When i create a new user its user_id and the station _id is not inserted
> into the "stations_users" table.I hav used scaffolding 4 creating these
> two models.How can i insert the fields for the join table also when a
> user is created?
> Can any one help me?
Not sure that this is your problem, but I wouldn't be surprised.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.