Rails中用於生成報告的RESTful路由

[英]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.

我正在使用Rails應用程序,該應用程序使用RESTful路由來處理它的資源。我現在正在創建一個報告控制器,它將生成HTML,XML,CSV等報告。根據發送到控制器的參數,將有幾種不同的報告可供生成。

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.

將REST用於此報告控制器是否過度,因為它不是一個將被保存然后可用於編輯或刪除的實際資源?使用RESTful會創建許多我永遠不需要使用的路由。

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?

定義自定義路線而不是RESTful會更好嗎?比如在生成報告的控制器中有一個生成動作並以指定的格式輸出它?

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

3 个解决方案

#1


0  

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:

我會以非RESTful的方式做到這一點。它不需要RESTful。甚至@jdl的答案也不是RESTful,因為它只包含一個動作節目。在這種情況下,報告不是可以創建,編輯或刪除的資源。我會添加這種路線:

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.

使用命名路由而不是連接將為您提供一些不錯的URL助手,如reports_path等。

#2


1  

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

你的方式很好,或者你更喜歡堅持使用RESTful路線,你可以選擇你想要的路線。

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

#3


1  

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.

根據RESTful Web Services,您不需要提供寫入操作,因此可以將您的服務視為RESTful。

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

據我所知,您需要使用ROA(面向資源的架構)設計您的服務,就是這樣。

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

話雖如此,@ jdl的答案是正確的,RESTful。 :)


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/02/22/725b3c17a7fedc35f36518318a0b5be1.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com