开发者

What is the right way of creating a nested view in rails

I have blog model. Blog has_many comments. I have created all the CRUD related to the blog. The comments doesnt have a page on its own. On the blog page, there could be text area and on the entering the comment, it would be saved thru ajax. But normally when a new page is created a new object is sent from the controller, so should i create a comment object and send it thru Blog's new action like this

  def new
    @comment = Comment.new
    @blog = Blog.new
  end

Or should i just access the comment objects present in the blog while creating the view

<form_remote_for @blo开发者_StackOverflow社区g.comments>

Which is the right way of doing this? Is there any better solution


Its preferred to have initialization of new comment in controller action. But its rather a guideline or practice I follow rather than the rule.

There is no form_remote_for tag. If its rails 2, tag is remote_form_for, similar thing in rails 3 would be:

form_for [@blog, @comment], :remote => true do |f|
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜