File downloads and REST

Hi,

How would an action that sends a file (build dynamically using data from
model) to user work in REST application? Is it ok if I add “download”
action to my controller and routes.rb (:collection => {:download =>
:get})? Or should it be done differently?

I cannot find anything in my resulting tree made with “rails something”.
I apologize if I’m missing something obvious.

xc

The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.

On 6/15/07, Szymon N. [email protected] wrote:

Hi,

How would an action that sends a file (build dynamically using data from
model) to user work in REST application? Is it ok if I add “download”
action to my controller and routes.rb (:collection => {:download =>
:get})? Or should it be done differently?

If you’re talking about resources, it makes more sense to make that
file it’s own resource.

map.resources :foos do |foo|
foo.resource :download # assuming there’s one ‘dynamic’ file per Foo
record
end

GET /foos/1/download # downloads/index action.

Part of the rails restful routing style was to stick to the core 7
actions (index, show, new, edit, update, create, destroy) by bringing
out the “inner resource”. This makes more sense if folks can also
update or destroy the extra resource. Then you wouldn’t need several
actions like show_download, create_download, etc.


Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com

Thanks.

Actually I don’t need to create a file for every resource item
(:foo),but thanks anyway - maybe I’ll add such functionality, now when I
know how to do it :slight_smile:

I’d like to be able to access results of my resources index action
(http://localhost/foos) in 3 ways - html format - by viewing it in a
browser, plain text - by getting data using GET “Accept: text/plain”
(works fine) and a plain text file, which would contain exactly same
results as previous option, but could be downloaded from the index page
by clicking a button.

How to do (correctly) something like that?

Hi, could you provide more info about your environment and the
webserver you’re trying to use?
Rails version? Webserver?

Thanks,

-Conrad

Conrad T. wrote:

Hi, could you provide more info about your environment and the
webserver you’re trying to use?
Rails version? Webserver?

Sure. Thanks. I’m on Ubuntu Gutsy (like unstable in Debian perhaps)
recently installed:

root@radioflyer:~/chapter-1# rails -v
Rails 1.2.3

I have this code in chapter-1/scripts/server:

root@radioflyer:~/chapter-1# cat script/server;echo
#!/usr/bin/env ruby
require File.dirname(FILE) + ‘/…/config/boot’
require ‘commands/server’
root@radioflyer:~/chapter-1#
–snip–
which differs from what I see on page 7 of Up_and_Running. Presumably
things have been radically refactored since that publishing.

xc

The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.


The only sustainable organizing methods focus not on scale,
but on good design of the functional unit,
not on winning battles, but on preservation.