# Ajax and Rails basic application

**URL:** <https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556>\
**Category:** Rails\
**Created:** [November 28, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556 "2007-11-28T22:17:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 28, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/1 "2007-11-28T22:17:52Z")

</div>

Hi all,

I have searched google for any basic Ruby on Rails application with  
Ajax. Any basic example where after clicking the button a webpage the  
application connects to the database and execute the query using AJAX  
and prints the information on the same page. Actually I have to give a  
presentation of a simple application of ruby on rails with Ajax.

Any information will be appreciated.

Thanks

Syed

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 28, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/2 "2007-11-28T22:23:23Z")

</div>

On Nov 28, 2007 3:17 PM, Syed R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I have searched google for any basic Ruby on Rails application with  
> Ajax. Any basic example where after clicking the button a webpage the  
> application connects to the database and execute the query using AJAX  
> and prints the information on the same page. Actually I have to give a  
> presentation of a simple application of ruby on rails with Ajax.
> 
> Any information will be appreciated.

To find Ajax info related to Rails, you might want to search for rjs:

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

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 29, 2007, 12:10am UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/3 "2007-11-29T00:10:13Z")

</div>

Greg D. wrote:

> On Nov 28, 2007 3:17 PM, Syed R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > I have searched google for any basic Ruby on Rails application with  
> > Ajax. Any basic example where after clicking the button a webpage the  
> > application connects to the database and execute the query using AJAX  
> > and prints the information on the same page. Actually I have to give a  
> > presentation of a simple application of ruby on rails with Ajax.
> > 
> > Any information will be appreciated.
> 
> To find Ajax info related to Rails, you might want to search for rjs:
> 
> [ruby on rails rjs - Google Search](http://www.google.com/search?q=ruby+on+rails+rjs)
> 
> –  
> Greg D.  
> [http://destiney.com/](http://destiney.com/)

greg is an expert. i would read his stuff.

here is the basics, but again, greg is da man.

:: put in the views layouts folder file name, header area  
\<%= javascript\_include\_tag :defaults %\>

:: put where you want the link to be. you can cut it down if you want  
\<%= link\_to\_remote ‘CLICK ON LINK NAME’,  
:update =\> ‘div\_area’,  
:url =\> { :controller =\> ‘name’, :action =\> ‘name’},  
:before =\> “$(‘indicator’).show()”,  
:success =\> “$(‘here’).visualeffect(‘highlight’)”,  
:failure =\> “alert(‘There was a failure error.’)”,  
:complete =\> “$(‘indicator’).hide()”  
%\>  
  
TEXT TO DISPLAY WHILE GETTING THE REMOTE LINK

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 29, 2007, 3:18pm UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/4 "2007-11-29T15:18:31Z")

</div>

Trent,  
I think there’s knowing it and knowing how to explain it. If the  
latter is the prize, you win it!  
I’m just completing a one year, 2000 hour Rails project with zillions  
of controllers and views and have always thought someday?? I’d get on  
the Java bandwagon. Thanks…  
What does the “here” mean in the :success statement? Would you expect  
the ‘stuff’ inside the “div\_area” to be a partial?  
I am grateful for any mentoring.  
Kathy

On Nov 28, 5:10 pm, Trent B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 29, 2007, 4:11pm UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/5 "2007-11-29T16:11:40Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Trent,  
> I think there’s knowing it and knowing how to explain it. If the  
> latter is the prize, you win it!  
> I’m just completing a one year, 2000 hour Rails project with zillions  
> of controllers and views and have always thought someday?? I’d get on  
> the Java bandwagon. Thanks…  
> What does the “here” mean in the :success statement? Would you expect  
> the ‘stuff’ inside the “div\_area” to be a partial?  
> I am grateful for any mentoring.  
> Kathy
> 
> On Nov 28, 5:10 pm, Trent B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

‘here’ is a typo on my part. doh! it is really ‘div\_area’

what will go in the div\_area is what is rendered by the :action.  
so if the action name has a matching file name in the views/app name  
folder, that is what is rendered.

if the action name, in the controller, is:

def time  
@t = Time.now.to\_s  
end

the views folder file named time.rhtml gets put in the div\_area.  
for example, just this one line will work in time.rhtml:

THE TIME IS: \<%= @t %\>

time.rhtml sits in the view folder of the controller that you are  
calling in the link\_to\_remote call.

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 30, 2007, 6:02am UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/6 "2007-11-30T06:02:21Z")

</div>

Hi Syed

Take a look at ActiveScaffold which has AJAX baked in…

CCH

> **[Rails... Rails... Rails](http://cch4rails.blogspot.com)**
>
> Chee Chong Hwa aka CCH, a Malaysian Chief Software Architect blogs on his experiences with Ruby on Rail running on Win2003 Server+Apache 2.26 environment since 2007. Flirted briefly with Ubuntu 9.04 in 2009. Since January 2017, now using RubyMine...

On Nov 30, 11:25 am, Syed R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![syed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a88e57/32.png) [@syed](https://www.ruby-forum.com/u/syed)\
**Post date:** [November 30, 2007, 4:25am UTC](https://www.ruby-forum.com/t/ajax-and-rails-basic-application/121556/7 "2007-11-30T04:25:07Z")

</div>

Trent B. wrote:

> removed\_email\_address@domain.invalid wrote:
> 
> > Trent,  
> > I think there’s knowing it and knowing how to explain it. If the  
> > latter is the prize, you win it!  
> > I’m just completing a one year, 2000 hour Rails project with zillions  
> > of controllers and views and have always thought someday?? I’d get on  
> > the Java bandwagon. Thanks…  
> > What does the “here” mean in the :success statement? Would you expect  
> > the ‘stuff’ inside the “div\_area” to be a partial?  
> > I am grateful for any mentoring.  
> > Kathy
> > 
> > On Nov 28, 5:10 pm, Trent B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> ‘here’ is a typo on my part. doh! it is really ‘div\_area’
> 
> what will go in the div\_area is what is rendered by the :action.  
> so if the action name has a matching file name in the views/app name  
> folder, that is what is rendered.
> 
> if the action name, in the controller, is:
> 
> def time  
> @t = Time.now.to\_s  
> end
> 
> the views folder file named time.rhtml gets put in the div\_area.  
> for example, just this one line will work in time.rhtml:
> 
> THE TIME IS: \<%= @t %\>
> 
> time.rhtml sits in the view folder of the controller that you are  
> calling in the link\_to\_remote call.

I really appreciate the input of everyone. Sadly I am too new with Rails  
and the only reason for me to take this path is to give a presentation  
about how to incorporate Ajax in Ruby On Rails project. I have three  
more days to present my presentation, so I think with what I have read  
about it in Ajax On Rails book and your responses, I think I might be  
able to pull it off.

People say that I am Java programmer and most of it I have learned  
writing,running and fixing real code. I will look in more about some  
working examples as that will help me create my own presentation.

Thank you very much, and I really appreciate all the responses and  
looking forward in using this knowledge in my project.

Thank you

Syed
