Thank you Peter for your reply!

I will look into that deeper, but I think first I have to get my
method run in the background.

I found delayed_job and I think that is exactly what I need, but I
can't get it to work!!!

My method in my controller looks like this:

  def check
    @watchedfamily = Check.new(params[:id]).watchedfamily
    redirect_to watchedfamilies_path
  end

That calls a very large model called Check, which looks like this:

class Check
  attr_reader :watchedfamily
  def initialize(id)
    @watchedfamily = Watchedfamily.find(id)
     .....
     ....
  end
end

I already tried in my controller:

Check.new(params[:id]).delay
or
Delayed::Job.enqueue(Check.new(params[:id]))

For the second try I changed my Check-Model like this:

class Check < Struct.new(:id)
  def perform
    @watchedfamily = Watchedfamily.find(id)
     .....
     ....
  end
end

Nothing worked at all! With the last option I get a entry in my
delayed_jobs table at least, but its never executed. I also tried
"rake jobs", but there I get an error: rake aborted! Don't know how to
build task 'jobs'

I am in development and using WebBrick Server.

I really have no clue how to get this to work!!!

Kind regards
Sebastian


On 12 Mai, 14:41, Peter De Berdt <[email protected]> wrote:
> On 12 May 2011, at 13:19, Sebastian wrote:
>
>
>
>
>
>
>
>
>
> > I have a button that links to a controller which is updating all my
> > entries in my db with new data, called from an external xml-based web
> > service. That can take several minutes, so I want to show the actual
> > progress in the view.
>
> > What is the best approach to do that? Java, AJAX...???
>
> > I found many 'upload progress bars', but I don't want to upload a
> > file.
>
> > I don't need a bar, it would be enough to show how many records are
> > left for updating, like this:
>
> > 1/37
> > ...
> > 11/37
> > ...
> > 25/37
> > ...
> > 37/37 done!
>
> > Best way would be without refreshing the page!
>
> You hand the task over to a background server, whichever flavor you  
> prefer (Nanite+Redis, Beanstalkd, …). This means you can keep on  
> serving other requests while the task is being done, as well as having  
> your user browse to another page (and when he requests the status  
> page, you just fetch the current progress).
>
> There's several ways you can pass the progress to the view:
> - Periodical polling through Ajax
> - Some push server technology (there's a Railscast athttp://railscasts.com
>   on this subject)
>
> Best regards
>
> Peter De Berdt

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to