Controller actions without CRUD

This may seem like a n00b issue, but I'm trying to break some of my bad practices that I may have used with MVC, so I hope you can help me

So, imagine that I want to do something like “Download CSV and Parse It”, it does not seem obvious to me that it fits into the CRUD template ... I don’t interact with the database, so I don’t know if I need to add or update or delete, but I still want to be able to use the action in a meaningful way from different views. Thus, this “normal” is simply an action called “UploadCSV” and access to it through a URL, for example “/ data / uploadcsv”

Your thoughts are greatly appreciated!

Tom

+3
source share
3 answers

It sounds like you're talking about RESTful ideas (having actions called an index, create, new, edit, update, destroy, show).

In MVC, you can call an action basically no matter what you want (so yes, you can call it uploadcsv if you want). If you want it to follow RESTful principles, you might need to think about what the action does (for example, loading data, essentially a create or update function) and name it using one of the RESTful action names.

+1
source

. , , , - - ( ) csv. , , CSV . ? -, ? , - . ?

0

, , .

, . , , " "

, "", csv, REST CSV.

, . csv. , :

map.resources :clients, :member => { :uploadcsv => :get }

The route is correctly declared, your customer resource calms down completely, and you have an additional action correctly declared to manage data import.

The only warning I have is: do not use a route like "/ data / uploadcsv". From my point of view, it has no clarity. I like to understand what my application will do just by looking at the URL. And '/ data' is too vague for me :)

0
source

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


All Articles