Ruby on rails display data with a certain parameter?

Have a model order, the model has the active property. I need to show all orders or only those that are active at the moment how to do it in REST terms?
July 2nd 19 at 17:22
2 answers
July 2nd 19 at 17:24
  • for all ${host}/api/rest/orders
  • only active ${host}/api/rest/orders?activ=true
${host} your host, respectively.
July 2nd 19 at 17:26
All /orders (OrdersController#index)
Active /orders/active (OrdersController#active)
Unfortunately it is not the REST. active is not an entity. - barney.Schroeder90 commented on July 2nd 19 at 17:29
In the guides say, you can add RESTful actions - guides.rubyonrails.org/routing.html#adding-more-re...
I assumed that the question is based on REST exactly in the application to the rails.
For me it is more Rails-way, than /orders?active=true - Elbert.Runte commented on July 2nd 19 at 17:32
I agree, being really on fraimwork have to live with its rules.
Then I can't argue (I'm not from the world of Ruby/Rails), maybe it's the Rails-way.
But it is not REST. - barney.Schroeder90 commented on July 2nd 19 at 17:35
: how to the url to determine rest or not rest? Sorry for possible stupid question - kade.Bos commented on July 2nd 19 at 17:38
:
The question is not stupid, and very rasprostronenie really.

On the basis of one can not say anything.

google.com it's REST?

REST is researchorientated. That is, URL's skryvayutsya sosnoski or resources.

We can create (POST), update (PUT), delete (DELETE) or simply request (GET) there or not, and how what they present.
And all requests sostavljajut based on certain konvencii or format if you want. It's a bit naive formulation.

In this issue we are talking about the latter.
We have some collection (orders) and we want to filter only for the attribute is active.
This is so
${host}/api/rest/orders?activ=true

If we asked for the status of a particular product (e.g. id=15) from a specific order (e.g. id=5),
then
${host}/api/rest/orders/5/product/15 - barney.Schroeder90 commented on July 2nd 19 at 17:41
Izvenyayus for the mistakes, no Cyrillic at hand. - barney.Schroeder90 commented on July 2nd 19 at 17:44
: disappoint you, but although REST is a very stupid and confusing term, although some side
${host}/api/rest/orders?activ=true
like this definition, but more loyal and Rails way would be to create a resource ActiveOrders and watch it index:
/active_orders - bobby.Ratke commented on July 2nd 19 at 17:47
: You disappointed me :)
I Pastorius: this is probably a Rails way and the Rails for the best.
But it is not RESTful . - barney.Schroeder90 commented on July 2nd 19 at 17:50
Unfortunately, there is no any popular application which is fully consistent with RESTfull :)
I'm just saying that /active_orders - preferable /orders?active=true regardless of the language context or framework in terms of resource routing - bobby.Ratke commented on July 2nd 19 at 17:53
: Just for the sake of interest. How it will look inactive orders? - barney.Schroeder90 commented on July 2nd 19 at 17:56
Rather access to them? - barney.Schroeder90 commented on July 2nd 19 at 17:59
: just the way you thought /inactive_orders. Especially if a resource (such as the mail tab: better to do /inbox_emails, /unread_emails, etc instead of /emails?type=inbox.
Of course, if you have a very large list of filters to cause the REST mind them no one will, but this implies - that there is not one as a popular business application is in full compliance with RESTful interface - bobby.Ratke commented on July 2nd 19 at 18:02
I agree that a clean RESTful there. But it was in the question is not about that.
/emails?type=inbox

I would never do this.

Rather:

emails/inbox
emails/unread

inbox, unread is a sub-collection of all the emails, not the attribute, which should be assigned to one of the emails. - barney.Schroeder90 commented on July 2nd 19 at 18:05

Find more questions by tags Ruby on RailsRESTful API