English 中文(简体)
Call Sinatra 删除与j Query的路线
原标题:Call Sinatra delete route with jQuery

我对Sinatra说得很新,正在制作一个简单的折射镜,利用了CRUD的基本功能。

在后台,我有工作路线,并测试了一切。 我想纳入一些前端功能,并决定利用 j帮助。 我在酒吧有一部现行法典,在被点击时,对其中一件大事加一门。 我想包括一个“完成的任务”的纽芬兰语,它将以“完成”的类别来收集任务,而不是触发将任务从数据库中删除的西奈特拉路线。 目前的Sinatra路线是:

delete "/hub/note/:id" do
   n = Note.get params[:id]
   n.destroy
   redirect  /hub 
end

我如何把删除这些物品与“完成”类别联系起来。 任何帮助都非常有用。

最佳回答
问题回答

贵格文法。

$.post( /user/  + user.id, {_method:  delete }, function(result_data) {
  console.log( DELETE result , result_data);
}).error(function(){
  console.log("Error trying to DELETE");
});

In your Sinatra code

delete "/user/:id" do
  if request.xhr?
    content_type :json
    id = params[:id].to_i
    user = User.find_by_id(id)
    if !user
      status 404
      return {:success => false, :message => "Invalid ID supplied."}.to_json
    end
    user.destroy
    return {:success => true, :id => id, :message => "The User with ID #{id} was deleted."}.to_json
  end
  status 403
  return "<html><head><title>Error 403</title></head><body><h2>Expected an AJAX call.</h2></body></html>"
end

如果贵国的扫描仪不是modular 附录中还包括<代码>:method_override, real line with You other sets。





相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签