Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-pluginsredmine

Why is post request favoured over delete in rails?


I have seen this in a lot of code written using Ruby-on-Rails.

It seems that post requests are often preferred over delete ones

 def destroy 
  relation = IssueRelation.find(params[:id])
  if request.post? && @issue.relations.include?(relation)
    relation.destroy
    @issue.reload
  end
 end

I find this a bit strange, because it does not seem to follow the REST convention used so much in Rails.

Does this have to do with security, or is it present for compatibility with some old browsers that don't support the delete request?


Solution

  • You basically answered your own question, browsers aren't exactly great at supporting all HTTP verbs. There's a nice site where you can test what your current browser supports, have a look at what things fail, I'm sure you'll notice some with regarding delete, for example when redirects are involved:

    http://www.mnot.net/javascript/xmlhttprequest/