I'm having general structural issues with Rails 3 and the new routes.rb is getting me a bit confused. Thanks for any help or guidance.
I have a forum application with nested resources. There are sections, topics, and replies. The routes.rb structure looks like this:
resources :sections do
resources :topics do
resources :replies
end
end
My section.rb:
has_many :topics
has_many :replies, :through => :topics
My topic.rb:
belongs_to :section
has_many :replies
My reply.rb:
belongs_to :topic
And this is working wonderfully. Now here's where I'm confused.
I added a user controller using Devise, and have a working username login/logout system. I'm trying to connect the 'current_user' with replies and topics. I think I have a good idea on how to fix the models, but I'm very confused with what to do in the routes.rb file.
For user.rb, I believe I need to add "has_many :topics" and "has_many :replies, :through => :topics". And then In my topics I need to add "belongs_to :user". I believe reply.rb remains the same?
As for the routes.rb I'm kind of stumped. If I edit the routes and add users to it, I would get a path like sectionid/username/topicid/ but I don't necessarily need to store a username in a route like that. So do I nest user in-between sections and topics or can I leave user out of the routes.rb file.