views:

34

answers:

3

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 correctly. Firebug doesn't give me any errors. This occurs in both Firefox and Opera.

A: 

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
Sam
This works too if you're using the inbuilt helpers
MatthewFord
It is written like that. only difference is that the order of the :confirm and :method params is reversed. I switched them just in case that would matter, but it didn't.
herpderp
Are you declaring this in your routes file. This routes are only avaliable if you have map.resources :resource declared. At least this is how 2.3.8 does it, I haven't upgraded yet.
Sam
I do have resources :tags in my routes.
herpderp
post a your log file
Sam
I already put the only relevant log info in my original post.
herpderp
A: 

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.

MatthewFord
A: 

try button_to that works..

raven