OK, removed the "# GETs should be safe" part of the controller and it
worked.

 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
          :redirect_to => { :action => :index }

Does it really needs to be inserted inside the controller ?

--
Alberto

On Nov 25, 11:23 am, cardinallijr <[EMAIL PROTECTED]> wrote:
> Rick,
>
> You are right. I tried to do what you suggested with a new project and
> it really worked. But with my project it doesn´t work. Something is
> wrong with my project, I´ll try to discover later. Maybe something
> with pagination or the model, I don´t know. If I discover something I
> ´ll post the results later.
>
> Thanks for your help,
>
> --
> Alberto
>
> On Nov 25, 4:23 am, Rick <[EMAIL PROTECTED]> wrote:
>
> > Hey Alberto,
>
> > Here's what's in my
>
> > config/route.rb:
>
> >   map.namespace :admin do |admin|
> >     admin.resources :products
> >   end
> > =========
>
> > app/views/admin/products/index.html.erb
>
> > <% for product in @products %>
> >   <tr>
> >     <td><%=h product.name %></td>
> >     <td><%= link_to 'Show', [:admin,product] %></td>
> >     <td><%= link_to 'Edit', edit_admin_product_path(product) %></td>
> >     <td><%= link_to 'Destroy', [:admin,product], :confirm => 'Are you
> > sure?', :method => :delete %></td>
> >   </tr>
> > <% end %>
> > =========
>
> > app/controllers/admin/products_controller.rb
>
> >   def destroy
> >     @product = Product.find(params[:id])
> >     @product.destroy
>
> >     respond_to do |format|
> >       format.html { redirect_to admin_products_path }
> >       format.xml  { head :ok }
> >     end
> >   end
> > =========
>
> > And it works - check out this site:
>
> >http://icebergist.com/posts/restful-admin-namespaced-controller-using...
>
> > Rick
>
> > On Nov 24, 4:19 pm, cardinallijr <[EMAIL PROTECTED]> wrote:
>
> > > routes.rb
> > > -------------
>
> > > map.namespace :admin do |admin|
> > >     admin.resources :categories
> > >     admin.resources :subcategories
> > >     admin.resources :products
> > > end
>
> > > --
> > > Alberto
>
> > > On Nov 25, 12:15 am, "Ryan Bigg (Radar)" <[EMAIL PROTECTED]>
> > > wrote:
>
> > > > What's in your routes.rb file?
>
> > > > 2008/11/25 cardinallijr <[EMAIL PROTECTED]>
>
> > > > > Ryan,
>
> > > > > Nothing in application.rb. I migrated this app from rails 1.2 and now
> > > > > I want to create an admin control panel.
>
> > > > > admin/products_controller.rb:
> > > > > ------------------------------------------
>
> > > > > class Admin::ProductsController < ApplicationController
>
> > > > >  layout 'admin'
>
> > > > >  def index
> > > > >    list
> > > > >    render :action => 'list'
> > > > >  end
>
> > > > >  # GETs should be safe (see
> > > > >http://www.w3.org/2001/tag/doc/whenToUseGet.html)
> > > > >  verify :method => :post, :only => [ :destroy, :create, :update ],
> > > > >         :redirect_to => { :action => :index }
>
> > > > >  def list
> > > > >   [EMAIL PROTECTED] = Product.paginate(:per_page => 8, :page => params
> > > > > [:page])
> > > > >  end
>
> > > > >  def new
> > > > >   [EMAIL PROTECTED] = Product.new
> > > > >  end
>
> > > > >  def create
> > > > >   [EMAIL PROTECTED] = Product.new(params[:product])
> > > > >    if @product.save
> > > > >      redirect_to admin_products_path
> > > > >    else
> > > > >      render :action => 'new'
> > > > >    end
> > > > >  end
>
> > > > >  def edit
> > > > >     @product = Product.find(params[:id])
> > > > >   end
>
> > > > >  def update
> > > > >     @product = Product.find(params[:id])
> > > > >     if @product.update_attributes(params[:product])
> > > > >      redirect_to admin_products_path
> > > > >    else
> > > > >      render :action => 'edit'
> > > > >    end
> > > > >  end
>
> > > > >  def destroy
> > > > >   [EMAIL PROTECTED] = Product.find(params[:id])
> > > > >   [EMAIL PROTECTED]
> > > > >   end
>
> > > > > end
>
> > > > > --
> > > > > Alberto
>
> > > > > On Nov 24, 11:15 pm, Ryan Bigg <[EMAIL PROTECTED]> wrote:
> > > > > > What else is in your controller? Anything in application.rb?
> > > > > > -----
> > > > > > Ryan Bigg
> > > > > > Freelancerhttp://frozenplague.net
>
> > > > > > On 25/11/2008, at 11:11 AM, Alberto Cardinalli Jr. wrote:
>
> > > > > > > OK, first I tried to call logger.info 'message' but nothing was
> > > > > > > logged (development.log). After this I installed ruby-debug and 
> > > > > > > put
> > > > > > > an "debugger" instruction but the execution didn't stopped on that
> > > > > > > point. So I really believe that the destroy method isn't being
> > > > > > > called, but why?
> > > > > > > I know that is something really stupid but can't see what's wrong 
> > > > > > > ...
> > > > > > > Ryan, the controller is 'admin/products_controller.rb'.
> > > > > > > I will try to fix it using the link Rick suggested.
>
> > > > > > > Thanks,
>
> > > > > > > --
> > > > > > > Alberto
>
> > > > > > > On Mon, Nov 24, 2008 at 9:29 PM, Rick <[EMAIL PROTECTED]>
> > > > > > > wrote:
>
> > > > > > > Hey Alberto,
>
> > > > > > > Take a look at this site, I think it's pretty close match to what 
> > > > > > > you
> > > > > > > are trying to accomplish:
>
> > > > > > >http://icebergist.com/posts/restful-admin-namespaced-controller-using.
> > > > > ..
>
> > > > > > > Rick
>
> > > > > > > On Nov 24, 2:19 am, Ryan Bigg <[EMAIL PROTECTED]> wrote:
> > > > > > > > The link should be:
>
> > > > > > > > <%= link_to "Delete", admin_product_path(product), :method
> > > > > > > > => :delete, :confirm => "Are you sure you want to delete this
> > > > > > > > product?" %>
>
> > > > > > > > Just to clarify: the controller you mean is admin/
> > > > > > > > products_controller.rb, right?
>
> > > > --
> > > > Appreciated my help?
> > > > Recommend me on Working With 
> > > > Railshttp://workingwithrails.com/person/11030-ryan-bigg
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
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