RESTful Routes in Rails for Reporting

I am working with a Rails application that uses RESTful routes to process its resources. Now I am creating a report controller that will generate reports in HTML, XML, CSV, etc. Several different reports will be available for generation, depending on the parameters sent to the controller.

Is it possible to use REST for this report controller, since it is not a real resource that will be saved and then available for editing or deletion? Using RESTful would create many routes that I would never need.

Would it be better to define a custom route instead of switching to RESTful? For example, if the controller has one action generatethat generates a report and displays it in the specified format?

map.connect 'reports', :controller => 'reports', :action => 'generate'
+3
source share
3 answers

I would do it without RESTful. It is not necessary that it be RESTful. Even @ jdl's answer is not RESTful, because it contains only one action show. In this case, reports are not resources that can be created, edited, or deleted. I would add the following 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 connectwill give you some useful URL helpers, e.g. reports_pathetc.

0
source

, RESTful, , .

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

, .

According to RESTful Web Services, you do not need to provide write actions, so your service can be considered RESTful.

As far as I know, you need to create your service using ROA (Resource-Oriented Architecture) and what it is.

It is said that @jdl's answer is correct and RESTful. :)

+1
source

Source: https://habr.com/ru/post/1733959/


All Articles