def create
@comment = lots of stuff going on here but it works...
if @comment.save
flash[:notice] = "Successfully created comment."
respond_to do |format|
format.js
end
end
Ok and this is where I’m stuck, then the create.js.erb:
Where I’m stuck is calling the partial in create.js.erb… How do I
pass what Rails needs to populate the partial? Right now I get the
error: “Called id for nil, which would mistakenly be 4 – if you
really wanted the id of nil, use object_id” Thanks!
@sunny@comment does not exists inside the create action, and he needs
to
iterate over a collection , @comments
<%=escape_javascript(render :partial =>“comments/comment”, :locals =>
{:comments =>fill the comments collection…))%>
or
@comment = lots of stuff going on here but it works… @comments = fill the comments collection…
if @comment.save
flash[:notice] = “Successfully created comment.”
respond_to do |format|
format.js
end
end
@comments does not exists inside the response from create.js.erb so you
have
to build it there or in the controller’s create action before the
respond_to
block
sure, just do it like sunny said, you are only going to display one
comment
if you user $(".cmtBox").html() if want to add one to the top use
insertBefore().
Thanks. The JQuery is easy the problem is the partial in your sample
app displays a list of several comments were I want to send back to
the user just the recently submitted comment. Thoughts?
@radhames thanks but in create.js.erb I do not want comments, just the @comment that was just created via a AJAX post with the comment
controller’s create…
I’m using your comments code example in the link you listed, it’s
great
But your example in create.js.erb sends back ALL the comments for a
model, I just want to return the comment that was just created. Can
you show me how to do that in your example? What should craete.js.eb
look like?
Got it working by deleting everything and starting from scratch… Not
sure what was the problem but using the above helped me get it right
from scratch. Thanks everyone!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.