Ruby on Rails 3 - 渲染编辑表单而不是新表单?
你好 我在我的应用程序上创建评论功能,但是当用户添加评论并且我使用 *.js.erb 文件呈现新评论页面时,它会为用户刚刚发布的评论呈现一个“编辑”表单?
$('#pager').append("<%= escape_javascript(render :new) %>");
控制器编辑&新评论看起来像这样。
# GET /comments/new
# GET /comments/new.xml
def new
@comment = Comment.new
respond_to do |format|
format.js
format.html # new.html.erb
format.xml { render :xml => @comment }
end
end
# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end
我做错了什么?谢谢!
Hi
Im creating a comments feature on my application, but when a user have added a comment and I render the new comment page with *.js.erb file it renders a "edit" form for the comment the user just posted?
$('#pager').append("<%= escape_javascript(render :new) %>");
Controller edit & new for comment looks like this.
# GET /comments/new
# GET /comments/new.xml
def new
@comment = Comment.new
respond_to do |format|
format.js
format.html # new.html.erb
format.xml { render :xml => @comment }
end
end
# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end
What am I doing wrong? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您浏览以添加评论时,new 操作将运行。 create 操作通常在用户从new 表单中单击“提交”后运行。
查看create 操作以查看提交后呈现的视图。
The new action will get run when you browse to add a comment. The create action is generally run after a user clicks submit's from the new form.
Look in the create action to see what view is getting rendered after submission.