new_story GET /story/new(.:format) {:action=>"new", :controller=>"stories"}
edit_story GET /story/edit(.:format) {:action=>"edit", :controller=>"stories"}
story GET /story(.:format) {:action=>"show", :controller=>"stories"}
PUT /story(.:format) {:action=>"update", :controller=>"stories"}
DELETE /story(.:format) {:action=>"destroy", :controller=>"stories"}
POST /story(.:format) {:action=>"create", :controller=>"stories"}
Run Code Online (Sandbox Code Playgroud)
在网络工作中,我已经完成了其他技术,我只使用过GET和POST方法.但是在Rails中使用RESTful路由时,默认情况下,PUT和DELETE方法用于更新和销毁操作.使用PUT和DELETE的优点或需求是什么?我假设这些方法只是做POST的另一种方式 - 但为什么不坚持使用POST?
我是Ruby的新手,并且一直在通过Mr. Neighborly的Humble Little Ruby指南工作.在此过程中代码示例中存在一些拼写错误,但我总是设法找出错误并随后修复它 - 直到现在!
这是非常基本的,但我无法在Mac OS X(Snow Leopard)上使用以下示例:
gone = "Got gone fool!"
puts "Original: " + gone
gone.delete!("o", "r-v")
puts "deleted: " + gone
Run Code Online (Sandbox Code Playgroud)
我期待的输出是:
Original: Got gone fool!
deleted: G gne fl!
Run Code Online (Sandbox Code Playgroud)
我实际得到的输出是:
Original: Got gone fool!
deleted: Got gone fool!
Run Code Online (Sandbox Code Playgroud)
删除!方法似乎没有任何影响.
任何人都可以对这里出了什么问题有所了解吗?: - \
我正在编写一个ajax,当 url 包含常量时它可以工作,但当 url 包含变量时它不起作用,因为它不会被实际值替换。
$('body').on('click', '.deleteLayer', function () {
var layer_id = $(this).data('id');
confirm("Are You sure want to delete record with layer_id="+layer_id+"?");
$.ajax({
type: "POST",
url: "{{ route('layers.destroy',['layer' => "+layer_id+"])}}",
data: {_method: 'delete', layer:layer_id},
success: function (data) {
table.draw();
},
error: function (data) {
console.log('Error:', data);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
如果我使用一个值,假设是 50 而不是 layer_id 那么它就可以工作了!!!:
url: "{{ route('layers.destroy',['layer' => 50])}}",
Run Code Online (Sandbox Code Playgroud)
这是我尝试访问的路线:
DELETE | admin/layers/{layer} | layers.destroy
Run Code Online (Sandbox Code Playgroud)
如果我不在 url 中发送图层参数,我会收到以下错误
message :“缺少 [Route:layers.destroy][URI:admin/layers/{layer}] 所需的参数。(查看:/var/www/laravelapp/resources/views/layers.blade.php)”
为什么是layer_id,这里
url: "{{ route('layers.destroy',['layer' => "+layer_id+"])}}", …Run Code Online (Sandbox Code Playgroud)