Haha! The beard bit made me laugh :)

Well, in my model articles dont have a user association. They just
have comments and users can post comments to different articles

So basically article and user have a many to many relationship with
the comments being the join table (it contains both article_id and
user_id). The comments table also has an additional attribute, the
actual comment.

I guess the
has_many :articles, :through => :comments
reads funny. It could just as well been

has_many :articles, :through => :user_article

So, given this, when a new comment is being created, I would like to
be able to use a path like
user_article_comment_path([...@user, @article])
What should I put in my routes file to get this?

I can do this
map.resources   :users do |user|
    user.resources :articles do |article|
        article.resources :comments
    end
end

but this gives me unnecessary paths like
user_article_path
which I dont want. I hope this makes sense.

On Jan 29, 8:41 am, Aldric Giacomoni <li...@ruby-forum.com> wrote:
> Maulin pa wrote:
> > Here is the scenario, Articles have many Comments Users can write many
> > Comments for many Articles
>
> > The comments table contains both
>
> > user_id
> > article_id
>
> > as foreign keys
>
> > My models are set up like so
>
> > class User < ActiveRecord::Base
> >   has_many :comments
> >   has_many :articles, :through => :comments
>
> > class Article < ActiveRecord::Base
> >   has_many :comments
> >   has_many :users, :through => :comments
>
> > class Comment < ActiveRecord::Base
> >   belongs_to :users
> >   belongs_to :articles
>
> Wait.. what? A user has many articles through comments? Why, in the name
> of Yehuda Katz's beard, would you want to do that?
> A user has many articles
> A user has many comments
> An article has many comments
> An article belongs to a user
> A comment belongs to an article
> A comment belongs to a user.
>
> Go from there, that's what makes sense.
> --
> Posted viahttp://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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to