Hello Rick,

Thanks for you reply. Yes, the controller is "admin/products". With
rake routes I have:

DELETE /admin/products/:id {:controller=>"admin/
products", :action=>"destroy"}

I tried to call admin_products_path(product) like you suggested but it
shows me an error (You have a nil object ...). Calling
admin_product_path works but don't delete the product, it redirects to
the list action and the product remains there. Rails version is 2.1.1.
When I told you that I called the destroy method using the console,
what I did was execute "Product.find(3).destroy". Is there another way
to test a controller's method using the console ?

--
Alberto

On Nov 23, 8:58 pm, Rick <[EMAIL PROTECTED]> wrote:
> This might actually work :-)
>
>  <%= link_to 'delete', admin_products_path(product),
>          :method => :delete, :confirm => 'Are you sure?' %>
>
> Rick
>
> On Nov 23, 12:40 pm, Rick <[EMAIL PROTECTED]> wrote:
>
> > Hello Alberto,
>
> > In your view, what are you trying to say with [:admin, product].
> > Is it perhaps {:controller => "admin/product"}?
>
> > rake routes on your routes.rb shows:
>
> >  DELETE /admin/products/:id
> >                    {:action=>"destroy", :controller=>"admin/products"}
>
> > So you should be able to use:
>
> >  <%= link_to 'delete', products_path(product), :method => :delete,
> >       :confirm => 'Are you sure?' %>
>
> > Rick
>
> > On Nov 23, 8:24 am, cardinallijr <[EMAIL PROTECTED]> wrote:
>
> > > Hi all,
>
> > > I'm trying to implement an admin control panel for my application and
> > > everything seems to work fine, except when I try to call the destroy
> > > method from the view. I really tried to search for a solution, reading
> > > some routing rails articles, but can't figure out what's going on.
> > > When I call the method from the console it works. Calling it from the
> > > view redirects to the list action, but the product is not deleted.
>
> > > View:
> > > -------
> > > <% for product in @products %>
> > >    <%= link_to 'delete', [:admin, product],:confirm => 'Are you
> > > sure?',:method => :delete %>
> > > <% end %>
>
> > > My routes.rb:
> > > -------------------
> > > map.namespace :admin do |admin|
> > >     admin.resources :categories
> > >     admin.resources :subcategories
> > >     admin.resources :products
> > > end
>
> > > Controller:
> > > --------------
> > > def destroy
> > >   @product = Product.find(params[:id])
> > >   @product.destroy
> > >   respond_to do |format|
> > >     format.html { redirect_to(products_url) }
> > >   end
> > > end
>
> > > Thanks for your help,
>
> > > --
> > > Alberto
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to