# What's the most compelling way to do AJAX/Interactive applications with Rails?

**URL:** <https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282>\
**Category:** Rails\
**Created:** [March 7, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282 "2008-03-07T16:46:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 7, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/1 "2008-03-07T16:46:38Z")

</div>

Hi,

So as I’ve said before, I’m coming to Rails from ColdFusion. In  
ColdFusion 8, there is are strong, albeit somewhat templated AJAX  
features.

What sort of options are out there for AJAX with Rails?

Thanks,

Ron

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 7, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/2 "2008-03-07T18:48:00Z")

</div>

Ron wrote:

> What sort of options are out there for AJAX with Rails?

[http://www.google.com/search?q=rails+ajax](http://www.google.com/search?q=rails+ajax)

“Lots”

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 8, 2008, 2:30pm UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/3 "2008-03-08T14:30:25Z")

</div>

The “keyword” you may want to look into is “rjs templates”. These are  
ruby templates that allow you to “render” ajax actions and javascript  
effects. Other useful keywords to look into:

- remote\_form\_for
- form\_remote\_tag
- link\_to\_remote
- observe\_form
- observe\_field

Also, look here:

[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html)

It may take a little bit of time to become familiar but it is  
surprisingly easy to use javascript and ajax rails.

# /app/controllers/posts\_controller.rb

def create  
@post = Post.new(params[:post])  
respond\_to do |format|  
if @post.save  
format.js # renders create.js.rjs template  
else  
#…  
end  
end  
end

# /app/views/posts/create.js.rjs

page.insert\_html :bottom, ‘posts-list’, :partial =\> “post\_item”, :object  
=\> @post

That is a quick example of how easy it is to set up an rjs action. That  
is the basic code for having someone create a post which shows up on  
screen using ajax to load the new post.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 12, 2008, 12:44am UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/4 "2008-03-12T00:44:48Z")

</div>

Definately check out:

[http://ujs4rails.com/](http://ujs4rails.com/)

Unobstrusive Javascript for Rails. Awesome plugin that allows for  
applying those principles with rjs.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 11, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/5 "2008-03-11T18:10:52Z")

</div>

Hi Ron, coming from CF myself, I’ve faced the same issues. I  
originally tried using RJS (baked into rails), but it left me with the  
same feeling of using cfform tags. I’m also a fan of unobtrusive  
javascript and I couldn’t find an easy way to use those principles  
with rjs.

Currently, I’m creating a new app that uses dojo toolkit. It’s an app  
all done on one page (the public/index.html file) that uses all the  
rails controllers as json providers.

I like not being tied to one library.

---

<div class="post-metadata">

**Author:** ![ron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ecae2f/32.png) [@ron](https://www.ruby-forum.com/u/ron)\
**Post date:** [March 12, 2008, 12:49am UTC](https://www.ruby-forum.com/t/whats-the-most-compelling-way-to-do-ajax-interactive-applications-with-rails/131282/6 "2008-03-12T00:49:44Z")

</div>

On 12 Mar 2008, at 00:44, Nathan E. wrote:

> Definately check out:
> 
> [http://ujs4rails.com/](http://ujs4rails.com/)
> 
> Unobstrusive Javascript for Rails. Awesome plugin that allows for  
> applying those principles with rjs.

It’s not supported anymore, Dan W. posted his reasons and he’s  
perfectly right. Use LowPro instead and do it in Javascript itself.  
Using Rails 2 it’s perfectly possible to generate javascript with erb  
parsing and combining that with LowPro, you have a pretty powerful  
tool at hand.

Best regards

Peter De Berdt
