RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

Переведите на русский!

Avatar

for anyone using Postgresql, I beleive current_timestamp does not return in utc - I fixed it with the following:

named_scope :current, :conditions => "starts_at <= now() AT TIME ZONE 'UTC' AND ends_at >= now() AT TIME ZONE 'UTC'"

cheers

Avatar

Hi...I am getting the following error while trying to upload a jpg file using paperclip.

identify: no decode delegate for this image format `I:/temp/stream.2652.2' @ constitute.c/ReadImage/503.

Can somebody help me with this?

Avatar

I have this running fine. However, it seems that the javascript is either running before the controller has finished running, or the javascript is not able to use variables form the controller

Any thoughts on this one?

Michael

Avatar

I figured it out.

In Ruby 1.9, the to_s member of arrays changed. (So did the default functionality of spitting out an array directly).

You need to add .join to the end of of items.uniq in the autocompletehelper.rb.

As in "items.uniq.join" instead of just "items.uniq", so search and replace that you'll be fine.

Avatar

@Chris, it depends what cache store you are using. It defaults to file based store which you will need to set up some kind of cron task to remove old caches.

If you set it up to use a memcache store it will roll off the old caches automatically when it reaches the set memory limit.

Avatar

Hi guys,

Could anybody please tell me how to use bullets with my text?

Thanks

Avatar

Hey all, I'm having a bit of problem with this thing returning the data into the intended <div> no problem. However the actual div never becomes visible.

I'm using Rails 2.3.3 and Ruby 1.9.1. I have prototype and effect.js loaded.

Avatar

@EppO you wouldn't want to do that in case you wanted to add the ability to update a comment, the count wouldn't change.

I suppose in the limited functionality the blog Ryan uses that would work fine, but in the spirit of scaling using the cache_key will always work!

Avatar

Internet Explorer needs var added to new variables to avoid the 'Object or method not found'

// javascripts/dynamic_states.js.erb
var states = new Array();
<% for state in @states -%>
  states.push(new Array(<%= state.country_id %>, '<%=h state.name %>', <%= state.id %>));
<% end -%>

function countrySelected() {
  var country_id = $('person_country_id').getValue();
  var options = $('person_state_id').options;
  options.length = 1;
  states.each(function(state) {
    if (state[0] == country_id) {
      options[options.length] = new Option(state[1], state[2]);
    }
  });
  if (options.length == 1) {
    $('state_field').hide();
  } else {
    $('state_field').show();
  }
}

document.observe('dom:loaded', function() {
  countrySelected();
  $('person_country_id').observe('change', countrySelected);
});

I tried it and now it works fine...

Avatar

Looking forward to the recurring billing episode. Many thanks for the series on Paypal.

Avatar

Hi, the svn server in no working, can you bring an alternative?

Avatar

@James R. I think that would just be send_later(:deliver, your_params_here). That would be the same as Object.deliver(your_params_here). Is that what you were asking?

Avatar

your atom_feed_helper link seems to be dead.

Avatar

Nice screencast but is there any built in way to recover space from previously expired caches or would this have to be set up as some sort of a cron job to go through and delete the old ones?

Avatar

Still didn't explain what UserSession is all about.

Avatar

@wysRd, @ryanb - is there anyway you can use a namespaced task in the call_rake method? I'm looking to do backup:db:dump

Thanks

Avatar

In this use case, you can probably just use a counter cache on belongs_to association, as it will store comments_count information in Article table, so it will be updated each time a comment is inserted.
But anyway, good screencast showing this cool new feature although I don't see any other use case that caching for that one.
(Audio problems was not a big deal for me, it's understandable)

Cheers

Avatar

thnak you very best in formation

Avatar

Can anyone provide an example of using delayed_job with ActionMailer (deliver method with params)?

Avatar

Ryan, Thank you. I didn't have the mocha gem installed. Got a lot of "NoMethodError: undefined method `expects'/`stubs' for ...". But once I installed it, all the tests passed. - Mike

Avatar

Quitting script/server and relaunching seemed to fix this problem. I also did sudo gem install rails just in case, but I'm not sure if that's what did it. Also, you can find the proper config.action_controller.session codes in the source code linked above.

Avatar

@Brett, set config.action_controller.session to what? I'm getting the same error as Bret and Joe. And I'm a rails noob :(

Avatar

Foreign ID Question:

I am having the hardest time figuring out why the foreign ID field is not being automatically populated in my site, which I've based my form off of Ryan's spectacular tutorial (thanks Ryan). From what I understand, the foreign id is put into the task when the build method is called in the line "@project.tasks.build". Then the foreign id is saved in the Project model under the "existing_task_attributes" method. Is this all correct or is the foreign id populated in some other way?

Thanks,
Thomas

Avatar

Feedzirra needs information from the stored feed entries to get the update working. You can read more on this here: http://groups.google.com/group/feedzirra/browse_thread/thread/6eb16d9a6d4d168e#

Avatar

never mind - my environment.rb needed to have config.action_controller.session_store = :active_record_store

uncommented

Avatar

Everything works except I'm getting "ActionController::InvalidAuthenticityToken" when I try to login. I have uncommented the 'secret' in application.rb

Avatar

Not sure why I am seeing this, but when I do this exercise I receive the error:

Error: There's an error with this transaction. Please enter a complete billing address.

Did something change in the PayPal API to require billing address? Why did your example work without this information?

Avatar

Ryan,
quick and clean! another great screencast!

Avatar

Hey! Great episode Ryan.

I've also translated it to Prototype for those who don't want to install the JQuery library:

http://handyrailstips.com/tips/18-dynamic-page-caching-with-prototype

Cheers

Avatar

Hey,

I installed paperclip, but cannot create a migration for it. I try this:

script/generate paperclip user avatar

And get a long string of errors, starting with this:

/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:376:in `new_constants_in': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.empty?
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in `load_file'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in `require_or_load'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in `load_missing_constant'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'
from /projects/Vitae/vendor/plugins/paperclip.git/lib/paperclip.rb:113:in `included'

Any ideas? I can't find anyone else who's had this problem.

Avatar

Is there no built in way to let the user know when a job has finished processing?

Great tutorial Cheers

Ryan T

Avatar

@Michael H.

I think the reason it doesn't work that way is that they are trying to separate the different processes. Waking a process would require the different processes to know about each other, and this way they all work independently of each other. The amount of cpu time consumed by each process to poll when there is no work is really insignificant. The resources consumed when they are actually doing something is far more important, and that wouldn't be improved by a 'wake on demand' system. Also, the more direct interaction you have between the different processes, the greater the fragility of the whole system.

There are a few good reasons all of these systems all use this polling method. Your question is a good one, but there are reasons they are done this way in general. For certain specific cases, a 'wake on demand' system will make more sense, but in general, a polling system is going to be better.

Avatar

Hello Ryan,

I've tried starting up the job processes in production with the command:

script/delayed_job -e production -n 1 start

but I get this error:

/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- daemons (LoadError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./script/../vendor/plugins/delayed_job/lib/delayed/command.rb:2
from script/delayed_job:6:in `require'
from script/delayed_job:6

any ideas on how to fix it?

Thanks a lot.

Ivan

Avatar

This is one of the best episodes I have seen so far! great tips!

Avatar

I have been using Workling+Sparkling for a while in production and I have just tested DelayedJob. D.J is really easier to use and run. I would recommend that.

Avatar

Great tutorial by the way. Informative but annoying at how easy you make it look!

I used tutorial 1 but decided to use a partial to display each task, as I thought this made a lot of sense.

However, when I loaded up tutorial 2, you then create a partial to create tasks.

Is it possible to have two partials in the same view? And if so how do I go about it?

Avatar

With the default session store (cookies) the password will be stored in clear text on your pc.

It's worth looking at these links if you're concerned about how secure your login process is (you should be).

http://guides.rubyonrails.org/action_controller_overview.html#session

http://guides.rubyonrails.org/security.html

Avatar

Oauth and authlogic are covered really well in the documentation at http://github.com/jrallison/authlogic_oauth/tree/master. Ryan tends to plug gaps of stuff that you can't find anywhere else, I can't see the point in him reading the documentation there out into a screen cast myself.

Avatar

I kept getting odd errors from Firefox like:

File can't be saved because source file can not be read.

IE seemed to work fine, oddly enough. I specified a filename for the pdf in my controller and that fixed the problem with Firefox.

"prawnto :filename => 'foo.pdf'"

Avatar

Hi Ryan/All,

I've been working on some background tasks lately and was hoping delayed_job would be a solution, but it doesn't seem like it will be.

1) Does delayed_job handle job dependencies? Sometimes you need to spawn 2 jobs, where job 2 depends on job 1 being completed

2) How does delayed_job deal with concurrency, specifically in the development environment using SQLite3? We've found issues using SQLite3 with our current background job framework. So I'm wondering what will happen if you have some background jobs that actively query/update active record classes? I would expect SQLite::BusyExceptions to occur in heavy traffic/many job scenarios.

3) I also share the question from Brian about the ability to run jobs on a remote server. Our current solution is to have the job itself invoke the commands on the remote server, and then collect the results via POpen4.

Thanks for any additional info. I would love to use a community supported gem to handle my background jobs, but our home baked solution is the only thing that has worked so far.

Avatar

You can also use the following to invoke Rake tasks from Delayed Job.

http://geminstallthat.wordpress.com/2008/02/25/run-rake-tasks-with-delayedjob-dj/

Avatar

Ryan, great episode. I've been using Spawn:

http://github.com/tra/spawn/tree/master

It's quite a bit easier to set up and use compared to delayed_job - no migration and no rake task necessary. I was wondering, what do you see as the main advantages of delayed_job over Spawn?

Avatar

Is it possible to create reoccurring jobs like for every hour?

Avatar

It's really useful. Thank you!

But I'll guess, I'm gonna create a app/jobs directory instead using the lib dir.

Avatar

Ryan,

I have been watching this screencast series for along time now, but you still keep nailing episodes. This is no exception.

Thanks for the Structs, never seen that before.

Avatar

Nice!

If anyone has additional info on one of the following, please post it!

1. saving how far the job made it so that it can resume from a failure without duplicating work (particularly useful for newsletters as Ryan mentioned)

2. running the delayed_job worker process from a different server

Thanks!
Brian

Avatar

The one piece of information I was looking for: how are the workers informed about jobs - actively by asking (polling), or passively by being called? Turns out it's polling - the SAME as all the other options I've seen.

That makes it just as bad as all those other options. On a 2009(!) computer system it should be possible to implement something like that WITHOUT wasting CPU cycles on polling.

Why can't the piece of code that pushes the new job information into the database (delayed job) or into memcache (workling/starling) also directly wake a thus far sleeping worker? Why does everyone only write code that actively asks "is there new work for me?" "is there new work for me?" "is there new work for me?" as often as several times per second (here, delayed job, uses 5s by default I just read)?

Okay, on a modern CPU one might argue that it really does not matter. However, what troubles me is that the same kind of "oh it does not matter in the grand scheme of things" is applied a little too often - which is why today we need so much CPU power in the first place to run a library using a library using a library using a library running in a virtual system in a virtual machine in a virtual machine (this term does not only apply to vmware/xen/etc.) fully simulated PCs).

Yes, I'm ranting. I've just been informed about the n+1-th "even greater" background job processing plugin for rails - which STILL uses polling.