读书人

Rails 三 的删除方法不能用了 delete

发布时间: 2012-10-27 10:42:26 作者: rapoo

Rails 3 的删除方法不能用了 delete put
update:
先试试

#production.rbconfig.serve_static_assets = true


有view
<%= link_to "Delete", admin_question_path(question), :confirm => "Are you sure?", :method=>:delete %>

#生成如下<a href="/admin/questions/3" data-method="delete" rel="nofollow">Delete</a>


http://localhost:3000/admin/questions/4/edit#而不是http://localhost:3000/admin/questions/4/destroy

#routes.rbQuestionator::Application.routes.draw do |map|  root :to => "admin/dashboard#show"    namespace "admin" do    root :to => "admin/dashboard#show"    resources :questions  endendrake routesadmin_question DELETE /admin/questions/:id(.:format)      {:action=>"destroy", :controller=>"admin/questions"}


所以不是路由的问题,

然后,看到说换button_to 因为Rails 3用的javascript转换的rest对应的方法,如果,你的javascript加载和jquery加载冲突就会有问题
<%= csrf_meta_tag %><%= javascript_include_tag :defaults %><%= javascript_include_tag 'jquery-1.4.2.min','jquery.form','rails.js'%>



 <%= button_to "Delete", admin_question_path(@question.id), :method=>:delete, :class=>:destroy,:confirm=>"Are you sure?" %><form method="post" action="/admin/questions/244"  type="hidden" value="delete" />    <input data-confirm="Are you sure?" type="submit" value="Delete" />    <input name="authenticity_token" type="hidden" value="yApLSCAIIqDBeubxR7RflOo+BnDByQHgSJzhtKvIATM=" />  </div></form>


http://piotrsarnacki.com/2010/09/14/mountable-engines/

读书人网 >网络基础

热点推荐