Reputation: 5953
In Rails, should you be able to update a field using a URL. Is that called RESTful?
For example, should something similar to this work to update workorder.wostatus_id for workorder with id=2?
http://localhost:5000/workorders/2?wostatus_id=4
Thanks!
Upvotes: 3
Views: 434
Reputation: 1208
In the case you've provided that shouldn't work as updates should be performed via a PUT
request although if the URL was requested via PUT
then it should work.
Remember the idea is that:
GET
to access and retrieve dataPUT
to update dataPOST
to create dataDELETE
to remove dataEDIT: Often the actual parameter names can vary depending on the controller implementation so in rails you often find ?workorder[wostatus_id]=4
, where it will reference the model name.
Upvotes: 1
Reputation: 20757
You will have to call a URL to perform any updates, but you'll need to use a POST or PUT request. POST to create, PUT to update, but I believe Rails uses "data-action" attribute for PUTs, then actually calls POST behind the scenes.
Just putting the URL in a browser, like the one you gave, will by default perform a GET request, which should never be used to change data, only to retrieve it.
Here's a good tutorial that explains the basics of REST: REST API tutorial
The Rest for Rails screencast is pretty helpful, as well.
Upvotes: 1