# New Ajax and Rails tutorial

**URL:** <https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818>\
**Category:** Rails\
**Created:** [May 7, 2006, 1:20am UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818 "2006-05-07T01:20:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 7, 2006, 1:20am UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/1 "2006-05-07T01:20:34Z")

</div>

Hi,

I just published the first version of a small tutorial I’ve written on  
Ajax and Rails. It is called “How to paginate, sort and search a table  
with Ajax and Rails” (sorry, I didn’t manage to find a longer title !)  
and is available at :

[http://dev.nozav.org/rails\_ajax\_table.html](http://dev.nozav.org/rails_ajax_table.html)

There is nothing really new in it, it’s rather a compilation and  
adaptation of several Rails wiki pages.

As I am neither a Rails expert nor a native english speaker, I would  
greatly appreciate any feedback.

Thanks,

Julien

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 7, 2006, 1:41am UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/2 "2006-05-07T01:41:45Z")

</div>

Julien B. wrote:

> Hi,
> 
> I just published the first version of a small tutorial I’ve written on  
> Ajax and Rails. It is called “How to paginate, sort and search a table  
> with Ajax and Rails” (sorry, I didn’t manage to find a longer title !)  
> and is available at :
> 
> [How to paginate, sort and search a table with Ajax and Rails · dev.nozav.org](http://dev.nozav.org/rails_ajax_table.html)
> 
> There is nothing really new in it, it’s rather a compilation and  
> adaptation of several Rails wiki pages.
> 
> As I am neither a Rails expert nor a native english speaker, I would  
> greatly appreciate any feedback.
> 
> Thanks,
> 
> Julien

Thanks Julien,

I just did a quick glance but it looks really promising. Great  
explanations of theory and code.

Keep those tutorials coming!

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 7, 2006, 1:55am UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/3 "2006-05-07T01:55:25Z")

</div>

Thanks, Julien. It looks good. More stuff like this is needed. I’ll try  
it  
out in an app I’m working on and see how it goes, and offer any  
feedback.

It would be nice to put a link to it on the Rails wiki if you haven’t  
already. That way people can more easily find it.

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 7, 2006, 1:49pm UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/4 "2006-05-07T13:49:04Z")

</div>

i tried this (by cut and paste) and gets this  
([http://localhost:3000/item/list](http://localhost:3000/item/list)):

ActiveRecord::StatementInvalid in Item#list

Mysql::Error: Unknown column ‘conditions’ in ‘where clause’: SELECT  
COUNT(\*) FROM items WHERE (conditions)

RAILS\_ROOT: script/…/config/…  
Application Trace | Framework Trace | Full Trace

./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:180:in `execute’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/mysql\_adapter.rb:322:in  
`select' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:175:in `select\_one’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:16:in  
`select_value' ./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:518:in `count\_by\_sql’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/base.rb:511:in  
`count' ./script/../config/../app/controllers/item_controller.rb:18:in `list’

./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:180:in `execute’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/mysql\_adapter.rb:322:in  
`select' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:175:in `select\_one’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:16:in  
`select_value' ./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:518:in `count\_by\_sql’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/base.rb:511:in  
`count' ./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:853:in `perform\_action\_without\_filters’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/filters.rb:332:in  
`perform_action_without_benchmark' ./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' ./script/../config/../vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in `perform\_action\_without\_rescue’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/rescue.rb:82:in  
`perform_action' ./script/../config/../vendor/rails/actionpack/lib/action_controller/base.rb:369:in `process\_without\_session\_management\_support’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/session\_management.rb:116:in  
`process' ./script/../config/../vendor/rails/railties/lib/dispatcher.rb:38:in `dispatch’  
./script/…/config/…/vendor/rails/railties/lib/webrick\_server.rb:117:in  
`handle_dispatch' ./script/../config/../vendor/rails/railties/lib/webrick_server.rb:83:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’  
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/lib/ruby/1.8/webrick/server.rb:82:in `start’  
./script/…/config/…/vendor/rails/railties/lib/webrick\_server.rb:69:in  
`dispatch' ./script/../config/../vendor/rails/railties/lib/commands/servers/webrick.rb:59 ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:214:in `require’  
./script/…/config/…/vendor/rails/railties/lib/commands/server.rb:28  
./script/server:3

./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract\_adapter.rb:88:in  
`log' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:180:in `execute’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/mysql\_adapter.rb:322:in  
`select' ./script/../config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:175:in `select\_one’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/connection\_adapters/abstract/database\_statements.rb:16:in  
`select_value' ./script/../config/../vendor/rails/activerecord/lib/active_record/base.rb:518:in `count\_by\_sql’  
./script/…/config/…/vendor/rails/activerecord/lib/active\_record/base.rb:511:in  
`count' ./script/../config/../app/controllers/item_controller.rb:18:in `list’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/base.rb:853:in  
`perform_action_without_filters' ./script/../config/../vendor/rails/actionpack/lib/action_controller/filters.rb:332:in `perform\_action\_without\_benchmark’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' ./script/../config/../vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in `perform\_action’  
./script/…/config/…/vendor/rails/actionpack/lib/action\_controller/base.rb:369:in  
`process_without_session_management_support' ./script/../config/../vendor/rails/actionpack/lib/action_controller/session_management.rb:116:in `process’  
./script/…/config/…/vendor/rails/railties/lib/dispatcher.rb:38:in  
`dispatch' ./script/../config/../vendor/rails/railties/lib/webrick_server.rb:117:in `handle\_dispatch’  
./script/…/config/…/vendor/rails/railties/lib/webrick\_server.rb:83:in  
`service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/lib/ruby/1.8/webrick/server.rb:173:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/lib/ruby/1.8/webrick/server.rb:23:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start' ./script/../config/../vendor/rails/railties/lib/webrick_server.rb:69:in `dispatch’  
./script/…/config/…/vendor/rails/railties/lib/commands/servers/webrick.rb:59  
./script/…/config/…/vendor/rails/activesupport/lib/active\_support/dependencies.rb:214:in  
`require’  
./script/…/config/…/vendor/rails/railties/lib/commands/server.rb:28  
./script/server:3

Request

Parameters: None

Show session dump

* * *

flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 8, 2006, 12:56am UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/5 "2006-05-08T00:56:11Z")

</div>

Julien B. wrote:

> The error is as the code didn’t interpolate the “conditions” variables  
> in the item controller. Are you sure you have the following syntax in  
> item\_controller.rb ?
> 
> conditions = “name LIKE ‘%#{@params[:query]}%’” unless  
> @params[:query].nil?  
> @total = Item.count(:conditions =\> conditions)  
> @items\_pages, @items = paginate :items, :order =\> sort, :conditions =\>  
> conditions, :per\_page =\> items\_per\_page

yes. i have exactly those code in item\_controller.rb . im using rails  
1.0, ruby 1.8.4, mysql 5.0.x, ubuntu dapper beta.

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 7, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/6 "2006-05-07T19:49:25Z")

</div>

Hi,

> Mysql::Error: Unknown column ‘conditions’ in ‘where clause’: SELECT  
> COUNT(\*) FROM items WHERE (conditions)

That is a bit strange. I just tried to reproduce it here by using Mysql  
as database, but it works for me.

The error is as the code didn’t interpolate the “conditions” variables  
in the item controller. Are you sure you have the following syntax in  
item\_controller.rb ?

conditions = “name LIKE ‘%#{@params[:query]}%’” unless  
@params[:query].nil?  
@total = Item.count(:conditions =\> conditions)  
@items\_pages, @items = paginate :items, :order =\> sort, :conditions =\>  
conditions, :per\_page =\> items\_per\_page

Or maybe you could try with sqlite, but I don’t think the problem comes  
from the database used…

Thanks for the feedback,

Julien

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 8, 2006, 5:09pm UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/7 "2006-05-08T17:09:52Z")

</div>

Hi,

> yes. i have exactly those code in item\_controller.rb . im using rails  
> 1.0, ruby 1.8.4, mysql 5.0.x, ubuntu dapper beta.

Hmmm… Maybe you could try with a query parameter in your request, for  
example :

[http://localhost:3000/itm/list/?query=a](http://localhost:3000/itm/list/?query=a)

Or maybe you could replace he ‘conditions’ variable with ‘@conditions’ ?

---

<div class="post-metadata">

**Author:** ![juba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5daacb/32.png) [@juba](https://www.ruby-forum.com/u/juba)\
**Post date:** [May 8, 2006, 7:00pm UTC](https://www.ruby-forum.com/t/new-ajax-and-rails-tutorial/59818/8 "2006-05-08T19:00:34Z")

</div>

Julien B. wrote:

> Hi,

> [http://localhost:3000/itm/list/?query=a](http://localhost:3000/itm/list/?query=a)

if i try that, here’s the error:

Mysql::Error: Unknown column ‘conditionsname’ in ‘where clause’: SELECT  
COUNT(\*) FROM items WHERE (conditionsname LIKE ‘%a%’)

the word ‘conditions’ seems to be stucked.

> Or maybe you could replace he ‘conditions’ variable with ‘@conditions’ ?

if i do this, i get the same error as before:

Mysql::Error: Unknown column ‘conditions’ in ‘where clause’: SELECT  
COUNT(\*) FROM items WHERE (conditions)
