# Link\_to\_remote patterns/idiom

**URL:** <https://www.ruby-forum.com/t/link-to-remote-patterns-idiom/126883>\
**Category:** Rails\
**Created:** [January 23, 2008, 2:14am UTC](https://www.ruby-forum.com/t/link-to-remote-patterns-idiom/126883 "2008-01-23T02:14:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [January 23, 2008, 2:14am UTC](https://www.ruby-forum.com/t/link-to-remote-patterns-idiom/126883/1 "2008-01-23T02:14:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [January 23, 2008, 2:47am UTC](https://www.ruby-forum.com/t/link-to-remote-patterns-idiom/126883/2 "2008-01-23T02:47:08Z")

</div>

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 W.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> if @comment.save  
> end

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.
