Wednesday, April 6, 2011

Why I can't change the link_to become link_to remote directly?

I have a link_to like this:

<%= link_to 'X', category, :confirm => 'Are you sure?', :method => :delete %>

So, I change it like this:

<%=link_to_remote category.name,
            :confirm => 'Are you sure?', :method => :delete%>

it show the confirm box, but after I click "yes", it won't delete the item I want , why?

From stackoverflow
  • There is no information about what url you need to go to in your link_to_remote usage. You should also specify something like

     :url => delete_category_path(category) 
    

    in the options hash.

    Ted Wong : because this method is calling on the /views/store, it is not calling the /views/categories, so, I have this error occur, how can I add the "delete_category_path" NoMethodError in Store#manage Showing app/views/store/manage.html.erb where line #13 raised: undefined method `delete_category_path' for #
    Ben Marini : The answer above assumes you have defined category as a resource in your config/routes.rb file. Doing that will add *_path and *_url helper methods, including the `delete_category_path`
    neutrino : thanks Ben also you can always use the :url => { :action => "...", :controller => "..." } form

0 comments:

Post a Comment