https://github.com/rdpoor/righteous_ujs
and the experience has convinced me that Rails controllers need a
#delete method that parallels the contracts of the #new and #edit
methods. To explain: The three "verbs" that cause a change to model
state are:
CREATE a model instance
MODIFY a model instance
DELETE a model instance
For each verb, the controller needs to implement TWO methods. The first
method fields the request from the user to initiate the action, to which
the controller responds by rendering a GUI element that allows the user
to complete the command. The second method is the result of submitting
the GUI element.
That's actually the contract of #new and #edit:
#new => render a GUI element that calls #create when submitted
#edit => render a GUI element that calls #update when submitted
The problem is with DELETE (aka #destroy). It doesn't follow this
pattern, but it should: the controller lacks a method that renders a GUI
element. It OUGHT to be:
#delete => render a GUI element that calls #destroy when submitted
Absent a #delete method, the Rails ends up relying on Javascript to
generate the GUI element that calls #destroy, which is Not Nice in a
system that claims to implement ubiquitous javascript.
This could easily be fixed by adding a #delete method to
ApplicationController which parallels #new and #edit. It would avoid
the issue about requiring Javascript, and as a side effect, would make
it really easy for newcomers to understand the relationship between:
#new => #create
#edit => #update
#delete => #destroy
Make sense? Is DHH listening? :)
Peace out.
- ff
--
Posted via http://www.ruby-forum.com/.
... which is exactly what I did in the cited code example.
I'm not sure how to interpret your reply. Sure it's trivial to add.
Are you claiming that a delete method should NOT become part of the
standard ActiveController?
No problem!
> ActionController::Base doesn't have *any* methods included.
You're right -- I mis-spoke:
s/"ActionController::Base"/"standard Rails distribution"/g
In addition to the resourceful routes, you'd need extensions to the
various generators and templates, but yep, that's what I'm arguing for.
> I can definitely see your case for wanting to do this.
Upon reflection, the right thing to do would be to open a lighthouse
ticket and let the pros decide. Wish me luck! :)
- ff
resources :events
I like the idea.
By the way, the issues are not on Lighthouse anymore but on GitHub:
https://github.com/rails/rails/issues
Alexey.
Right you are. So, feeling a little like David facing off against
Goliath, I've submitted a ticket:
https://github.com/rails/rails/issues/4234
I hope they go gentle on me!
- ff