You''re right about the myriad of options. You can either return an RJS
that
will update a div (with an id of comments) with the new comment contained
within a partial (_comment) from your app/views/comments directory.
(Complicated way)
Alternatively, you could just redirect to the item that you created a
comment for which will already (I hope) have a way of iterating over the
comments. You could then pass back a flash[:notice] stating the success or
failure of your comment posting. (Easy way)
On Jan 23, 2008 11:44 AM, Cory Wilkerson
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
> All,
>
> What''s the current line of thinking wrt patterns/best practices
for
> remote calls and subsequent page updates?
>
> For instance, let''s say I have a simple link_to_remote call that
simple
> creates a new comment for a given blog post. On success, I''d like
to
> indicate that all was well, on failure, I''d like to give some
indication
> as to why.
>
> Obviously, Rails has some nice (and by nice I mean ''programmer
> friendly'') abstractions for handling this type of functionality
but the
> myriad of options has left me in a state of paralysis.
>
> That said, I''m seeking to understand the preferred/recommended way
to
> pull something like this off:
>
> class CommentController < ApplicationController
> def create_comment
> @comment = Comment.new(params[:comment])
> if @comment.save
> # Should I use RJS here to update the page?
>
> # Should I return some HTML (sans RJS) and use the prototype
> helper to
> # update a DIV?
> else
> # Would obviously look to stay consistent here.
> # Do I use RJS to update the page?
> # Shall I send back a non 2XX status code and use prototype helper
> end
> end
> end
>
> What be the prevailing pattern? Arggh.
>
> TIA!
> Cory
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---