views:

128

answers:

2

I am working with a Rails application that uses RESTful routes for handling it's resources. I am now creating a reports controller that will generate reports in HTML, XML, CSV, etc. There will be several different reports available for generation, depending on the parameters sent to the controller.

Is it overkill to use REST for this reports controller as it's not an actual resource that will be saved and then available for editing or deletion? Using RESTful would create a lot of routes that I will never need to use.

Would it be a better practice to define a custom route instead of going RESTful? Such as having a single generate action in the controller that generates the report and outputs it in the specified format?

map.connect 'reports', :controller => 'reports', :action => 'generate'
A: 

Your way is fine, or if you prefer to stick with the RESTful routes you can pick and choose the ones you want.

map.resources :reports, :only => [:show]
jdl
+1  A: 

I would do it in non RESTful way. There is no need for it to be RESTful. Even @jdl answer isn't RESTful, because it contains only one action show. In this case reports aren't resources that can be created, edited or deleted. I would add this kind of routes:

map.report 'reports/:id', :controller => 'reports', :action => 'generate'
map.report_with_format 'reports/:id.:format', :controller => 'reports', :action => 'generate'
map.reports 'reports', :controller => 'reports', :action => 'index'

Using named routes instead of connect will give you some nice url helpers like reports_path etc.

klew