Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTful routes in Rails for generating reports

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'
like image 239
Trevor Avatar asked Dec 31 '25 00:12

Trevor


2 Answers

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]
like image 150
jdl Avatar answered Jan 01 '26 15:01

jdl


Sorry resurrecting such old post.

According to RESTful Web Services, you don't need to provide write-actions so your service can be considered RESTful.

As far as I know, you need to design your service using ROA (Resource-Oriented Architecture) and that's it.

That being said, @jdl answer was correct and RESTful. :)

like image 31
Davi Koscianski Vidal Avatar answered Jan 01 '26 13:01

Davi Koscianski Vidal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!