John B. wrote:
I followed your advice with the page.replace_html “This is a test” and
it turned out there was a problem with the partial.
I have used the following code below to render the post and comments
separetly but i will refactor this to make it add the comment to the end
of the comment list and update the no of comments on the end of the post
improving performane.
The extra end you suggested causes a syntax error but removing it
works?? Seems strange.
def comment
Post.find(params[:id]).comments.create(params[:comment])
@post = Post.find(params[:id])
render :update do |page|
page.replace_html( “postdiv”, :partial => “post”, :id => @post)
page.replace_html(“commentlistdiv”, :partial => “commentlist”,
:object => @post)
end
Thanks
I don’t know what’s going on in your code, but the snippet you posted is
missing an “end” for its “do”.
The “render :update” command takes a block as its parameter, and a block
is formed by “do … end”.
What you have there is:
def comment
…
render :update do |page|
…
end
See the problem?
You need
def comment
…
render :update <block_goes_here>
end
like so:
def comment
…
render :update do |page|
…
end
end
If what you posted is working, then you have an extra “end” somewhere
else or there’s some other kind of problem with your syntax.
If you’re having a problem with a partial, what I do is to go into the
partial and make it as simple as possible, start with something like
_post.rhtml
This is _post.rhtml
and then try it. If it you see “This is _post.rhtml”, then try adding
an instance variable:
controller:
def comment
@post = “This is a post”
render :update do |page|
page.replace_html “postdiv”, :partial => “post”
end
end
_post.rhtml:
<%= @post %>
and so on. Then when you see “This is a post”, you know that the
variable is making it into your partial, and you can replace it with the
proper assignment.
Another problem you may be having is the :id parameter in your partial
call–you might try taking it out and just referring to @post in your
partial.
I’ve had problems even sending local variables to partials from render
:update, so your best best is to just assign the variable in your
controller and use it in the partial.
Jeff