The destroy action:
def destroy
@tag = Tag.find(params[:id])
@tag.destroy
respond_to do |format|
format.html { redirect_to(tags_url) }
format.xml { head :ok }
end
end
The link:
<a href="/tags/14" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a>
Clicking it renders the show action.
Started GET "/tags/14" for 127.0.0.1 at Wed Oct 27 18:36:41 -0500 2010
Processing by TagsController#show as HTML
Parameters: {"id"=>"14"}
Tag Load (0.2ms) SELECT "tags".* FROM "tags" WHERE ("tags"."id" = 14) LIMIT 1
Rendered tags/show.html.erb within layouts/application (8.5ms)
Completed 200 OK in 25ms (Views: 12.1ms | ActiveRecord: 0.2ms)
javascript_include_tag :defaults is included on my page and the script tags render correct开发者_Go百科ly. Firebug doesn't give me any errors. This occurs in both Firefox and Opera.
It's probably how you are writing your link_to method.
<%= link_to "Destroy", tag, :method => :delete, :confirm => "Really?" %>
Try that.
Make sure you have the resource declared in your routes.rb file as that is what gives this freebee urls.
in 2.3.8 it is
map.resources :tags
in R3 I don't really know but the guides have it like this
resources :tags
To use method overriding you need to be sending the _method
parameter. For an action like destroy it should be a form that you POST with the _method
parameter set to delete
, you can construct the form in JS when you click the link if you like.
精彩评论