开发者

In Rails, I'm trying to pass an attribute to a Model's "new" method, then to the "create method". What's the most efficient way to do this?

In my Rails application I have a Forum with many Topics. From the Forum's, "show" page I have a list of Topics with a link to create a new Topic. My goal is to make sure that when creating the new Topic I have the ID of the Forum when I get to the Top开发者_如何转开发ic's "create" method. Right now I'm thinking I'd have to create a hidden field on the Topic's "new" page and set the hidden field to the Forum's ID. I was wondering if there is a better, cleaner way.

Thank you for looking!


Nested resources are the way to go for this, so you nest the Topic resource within the Forum resource. Take a look at these tutorials:

  • Nested Resources Rails Guide
  • Nested Resources Railscast
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜