Ruby on rails 3 - Rendering edit form instead of a new form?
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开发者_如何学Go => @comment }
end
end
# GET /comments/1/edit
def edit
@comment = Comment.find(params[:id])
end
What am I doing wrong? Thanks!
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.
精彩评论