RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

You are the most awesome person in the world! Looking forward to the next episode! Thanks a lot as always!

Avatar

I'm having the same issue as @Alexandre (Rails 2.3.3)

Avatar

Does anyone have a code sample for a daemonized version of this? I'm not quite sure how to get the initial statement to run only once within daemon_generator's while clause.

I used the code as is, but it will never terminate since it will never complete the while($running) loop because of the update loop.

Avatar

I just created a plug in that uses delayed_job to send emails asynchronously by default.
Check it out at http://github.com/andersondias/delayed_job_mailer

Avatar

Does it trigger callbacks) on the parent instance ?

Avatar

Does anyone know how to get the "worker" started automatically instead of having to type "rake jobs:work" in a console? Ie. make it start when the server starts or something.

Nice tutorial btw, it was exactly what I was looking for! :-)

Avatar

Hi guys,
just wanted to let you know that I did a write up of how to go about adding Javascript to paginated content. It's all on my blog: http://thinksimple.pl/entries/83-AJAX-pagination-with-Javascript

Avatar

Isn't this line missing a right parenthesis:

$(".pagination a").live("click", function() {

Avatar

i use will_paginate any suggestion to NOT limit my rss shows 3 post (paginate) ??

any help please?

Avatar

Ryan,
Great screencast. I'm having problems though. Instead of categories I'm using departments. I'm also using NetBeans 6.7 for my IDE. Everything is going great until I load the edit page, then in the NetBeans Console is an error:

DEPRECATION WARNING: formatted_departments_path() has been deprecated. Please pass format to the standard departments_path method instead..

I'm not sure where to go from here.
John M

Avatar

Great and timely article and thanks to Mislav for posting his prototype solution (which works great btw).

@Joseph Silvashy
LMAO!!!

Avatar

current_user getting error in this.

Avatar

Thanks for information :)

Avatar

Thank you for choosing to make this demonstration with jQuery. Most people I know using Rails these days wants to or is using jQuery.

Avatar

I got to the part where you illustrate an ajax request from index.js.erb by sending the alert "this is an ajax request" and I get a javascript "syntax error" in my firebug console. I never see the alert so of course the ajax doesn't work for me.

What could that be? I'm using jQuery 1.3.2. Thanks for any help!

Avatar

Thenks for information

Avatar

Excellent, I've had all this before, but you did show me how amazing the live() function is, and in fact, I'm incorporating this in my site. At some point there was a jQuery plugin called jQuery Live, and it did this and more, like combining both adding things to the dom and binding the events.

Anyhow thanks Ryan, also like to mention that your site is the best screencast site ever and the best deals on um... designer bags and shoes.

Avatar

It didn't works for me, the result of the request returns, but it's like the javascript didn't interpreted and the returns didn't been showing.
Can you help me, please?

Avatar

Ryan, you might want to fix your RDOCs for the Gem. You have the same "from_now" mistake in them. :)

Otherwise, great screen cast, as always.

PS: I love Populator (and Faker).

Avatar

Prototype.js users: the will_paginate wiki had sample code similar to this railscast for a long time now: http://wiki.github.com/mislav/will_paginate/ajax-pagination

Take a look even if you're not using Prototype.

@Ryan: something you should know about jQuery "live" method: it doesn't re-apply the event handlers to new elements inserted in the DOM. That's what the (now obsolete) plugin called "livequery" was doing. The current jQuery "live" method uses a modern and correct approach: event delegation.

Prototype.js doesn't yet have event delegation support (that's coming in a future release), but event delegation is fairly easy to use manually. I'm using it in the example code on the wiki page linked above.

Avatar

Solved:
comment out environment.rb entry , config.gem "nifty-generators" once rake gems:install executed.
Weird.

Avatar

I'm getting a similar problem to John:
$ sudo gem install nifty-generators
Password:
Successfully installed nifty-generators-0.2.4
1 gem installed
Installing ri documentation for nifty-generators-0.2.4...
Installing RDoc documentation for nifty-generators-0.2.4...
$ script/generate nifty_scaffold
no such file to load -- nifty-generators
...
Missing these required gems:
  nifty-generators

You're running:
  ruby 1.8.6.287 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
  rubygems 1.3.4 at /Users/robert/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8

Run `rake gems:install` to install the missing gems.

Any clues?

Avatar

What if next version of will_paginate changes class name of a pagination container div? Your code will simply stop working. Suddenly.

This solution relies on external library internals (external internals; I like that), which makes it a bit of a hack.

Still, a great demonstration of technique. Thanks!

Avatar

Ok... github told me that my gem mill Manifest file, maybe you should correct the post, becouse in it you told us to add Manifest file in .gitignore

Avatar

This is the url on github

http://github.com/redvex/ar_cache/tree/master

Avatar

load my gem in github but...

ERROR: could not find gem redvex-ar_cache locally or in a repository

can you help me?

Avatar

@richard

Quite agree in this case it is not needed to add noscript however brian wanted to know how to detect if Javascript is enabled

Avatar

Amazing , unquestionably fabulous ... is there anything like jQuery "live" for prototype ?? thanks alot .

Avatar

You use a nice little helper called javascript to add to the list of javascript loaded on each page. Is this a plugin ?

Avatar

Geoff you don't need to add the noscript ugliness as it will work as a regular link without javascript turned on.

Avatar

For those who wanted to try this, keep in mind that this requires that Red Cloth be installed in order to utilize textilize:

http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M001748

. To install it:

gem install RedCloth

Then add:

require "RedCloth"

To your environment.rb file.

For more information on setting it up, go here:

http://redcloth.org/

Avatar

@brian

Just add to any HTML page

<noscript>Your Browser Has Javascript disabled. Enable It</noscript>

Avatar

Nice Screencast. Was wondering what a good approach would be to accomplish this.

Looking forward to next weeks screencast to see your take on handling the history-variant of this.

Makes it easy enough to just implement in a few minutes as a progressive enhancement element. Great!

Avatar

I still dont understand where it creates the user_sessions database...

I followed the screencast and i still get :

 Showing app/views/user_sessions/new.html.erb where line #7 raised:

undefined method `username' for #<UserSession: no credentials provided>
 
I have run the script/renerate session... and script/renerate nifty_scaffold with --skip-model...

Any ideas?

Avatar

Simplify that code! Use $.getScript(url)

Avatar

Anton, on this
`parent_name': can't modify frozen object
error - I just had the same with Rails 2.2, and managed to fix it with class caching setting:
config.cache_classes = true

Avatar

Thanks Ryan. Great video. For anyone interested, here is how to do similar in merb, but with a 'more' pagination similar to twitter's instead.

http://scottmotte.com/archives/217.html

Avatar

unintrusive => unobtrusive

Avatar

Hi!

Thank you for introducing the unintrusive JavaScript topic. I learned only a few months about this by a talk from DHH, who said Rails 3.0 will use unintrusive JavaScript, which seems a very good idea (especially for Prototype deserters like me).

But actually I don't think that pagination is a good example for the usage of ajax. Pagination will usually change large potions of the visible text (more than 90%), so I think it's better to traditionally load the page.

Also you have to remember lot's of things the user expects from a paginated list, like you said, giving the user a proper loading feedback or the usability of the back and next button. Also, the user expect the page to return to the top, if the page was scrolled down. There are probably other usability expectations as well.

Don't break an expected and learned behavior without a good reason.

Avatar

Monday's just wouldn't be the same without your excellent screencasts.
Also, I agree that maybe a series of BDD/TDD approaches to creating a solution would be helpful ... it would be nice to compare techniques.
Gotta go watch this screencast :-)

Avatar

Excellent screencast!

Lots of info packed on this one, thank you!

Avatar

@Millisami, I saw that extra parameter also... you can work it out by moving the pagnation links from the products partial into the index view...

Thanks

Avatar

Great screencast!! and thanx as always.

I'm concerned about the ?_263635377 parameter that is appended in those page links?

I've too seen this in my own project and haven't figured out what that is coz it doesn't break the funcationality. just curious!!

Avatar

Great screencast Ryan. I did something similar to this on one of my own sites recently. Looks like it may be easier to use the live method as opposed to my own event bubbling solution. Anybody know if there is any kind of a performance hit in using live versus defining a normal click handler on a parent element and detecting the target?

Ryan, for future screencasts, could you consider doing them from a TDD/BDD approach? I know you've done some screencasts on testing, but I think tackling them from a TDD/BDD approach on a regular basis would help people (myself atleast) get into the same habits themselves.

Thanks,
Chris

Avatar

Yep I think the solution posted by Dave Shenk is simpler:
http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links

This is what I used in the past. Perhaps the downside to it (and why you didn't include it) is that it doesn't fall back for people who have javascript turned off?

Probably 90% of the stuff on my site doesn't work without JS. Actually that would be a good railscast...how to display a generic message to people who have JS turned off, like basecamp. Thanks!

Avatar

Here's another slightly different solution to get you a similar result.

http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links

Avatar

Thank you Ryan, like Adam I am really looking forward to the next episode because I think AJAX pagination like in this episode breaks the UI. Losing URL/history is always a high price for AJAX.

Avatar

Great cast as always.
I use the same technique for my projects. I will be great in some of the future screen casts you show sprockets for managing js dependencies.

Avatar

I can't get it to work inside partials either. An issue have been raised on Lighthouse:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1896-content_for-not-rendering-from-partials-in-layout

But it seems that DHH invalidated it. Maybe it should be reopened?