Keith,

   ah, the fog begins to dissipate; you have 2 controllers for the same
resource: one for administration, the other for the 'public' (it would have
simplified a lot the discussion if you had said it from the start..).

This means:
a) first, the line 'map.resources :products' generates the routes used by
the Products controller; so, it cannot be removed or tinkered with (as then
the normal album would stop working).

b) I still think that it is a terrible idea to have one section of your site
working with Restful routes (just because you generated it with scaffold)
and another section (on the same resource!) with old-style routes (just
because you generated this part manually).

I then suggest this approach:

1) instead of having the 2 controllers named as 'albums' and 'public', I
would suggest this:

    Admin::AlbumController  and Album

2) to obtain that, write in routes.rb:

  map.resource :admin do |admin|
    admin.resources :albums, :name_prefix => 'admin_',
                                      :controller=> 'admin/albums'
  end

  map.resources :albums

3) you already scaffolded the 'Albums' controller. Use that for the public.
For the admin, do:

  script/generate controller 'admin/albums'

[If you use NetBeans, it should be obvious the mapping between the unix
commands to the Gui].

Begin to work with that, and see if you like the idea.

Last: are you sure you really need 2 controllers? there is the possibility
to have only 1 controller and detect from the user if it is an admin or not.
See:
http://www.fallenrogue.com/articles/178-Creating-a-RESTful-admin-section-in-Rails

(Although the author was using Rails 1.2.2 at the time, he already was on
Rest...).

Raul


On Mon, Oct 20, 2008 at 3:28 PM, <[EMAIL PROTECTED]> wrote:

>
> Raul,
>
> I do have a scaffolded 'Album' and I also have a Controller called
> Albums. The controller called Albums should of been called Admin but
> as far as I can tell, there is no way to build scaffold around a table
> without using that table name as the default for all your files.  I do
> not think this is possible in Rails 2.1 where as in the old rails you
> could use - scaffold :album
>
> Correct me if I'm wrong  the only reason when I clicked on destroy and
> it was'nt redirecting me to the action that I wanted it to is because
> in my AlbumsController there is
> def destroy
>    @album = Album.find(params[:id])
>    @album.destroy
>     respond_to do |format|
>      format.html { redirect_to(albums_url) }     ******* I think this
> may of been the reason why it was picking up another action, is this
> right in thinking so?
>      format.xml  { head :ok }
> would this override what I have in my PublicController?***********
>    end
>  end
>
> Just one more question Raul how did you know that I had a
> scaffold :album?
>
> Thanks
>
> Keith
>
>
> On Oct 20, 10:25 pm, "raul parolari" <[EMAIL PROTECTED]> wrote:
> > Keith,
> >
> >    there is something odd; you have scaffolded 'Album', but then you
> called
> > the Controller 'Public'.. no wonder that Rails is confused. Is there a
> > reason that you need to call your controller "Public"? it does not make
> > sense as a name for a controller, and moreover if you call it Album,
> > everything will be easier; you would go with the Rails wind, not fight
> > against it.
> >
> > Also: using Urls like '/public/destroy/id' is really going back to Rails
> 1.
> > The action 'destroy' (or 'create', etc) should not be part of the Url;
> this
> > is the reason that we  specify :method  => :destroy.
> > If you wanted to use '/public/destroy/id' then you should remove the
> > ':method => :destroy'. However, beware that this is not a good design.
> >
> > I suggest you to read the AWDWR book that you mentioned: see how they
> obtain
> > the 'product' controller and model, and how they end up with clean Urls
> and
> > helpers:
> >
> >      <%= link_to 'Show', product %><br/>
> >      <%= link_to 'Edit', edit_product_path(product) %><br/>
> >      <%= link_to 'Destroy', product, :confirm => 'Are you sure?',
> >                                        :method => :delete %>
> >
> > I think that if you used these techniques not only you would simplify
> > tremendously your work, but you would also learn something valuable
> (instead
> > of those insane tips like '/public/destroy/37' from those blogs and
> forums,
> > that teach the wrong way to do things)
> >
> > Raul
> >
> >
> >
> > On Mon, Oct 20, 2008 at 12:36 PM, <[EMAIL PROTECTED]> wrote:
> >
> > > Hi Raul,
> >
> > > I did as you suggested without editing the routes.rb file and I still
> > > managed to come up the ' Unknown action No action
> > > responded to destroy'
> >
> > > <%= link_to  'Destroy', {:action => 'destroy', id =>
> > > @album.id},
> >
> > >                                      :confirm => 'Are you
> > > sure?',
> >
> > >                                      :method => :delete %>
> >
> > > However I did managed to find another comment with the same type of
> > > issue, which was
> > > <%= link_to 'Destroy', movie, :confirm => 'Are you sure?', :method
> > > => :delete %>  which was from
> > >http://fairleads.blogspot.com/2008/01/this-is-second-part-of-my-serie.
> ..
> > > .
> >
> > > With this information I replace the following
> >
> > > # replace the line
> > > <%= link_to  'Destroy', {:action => 'destroy', id =>
> > > @album.id},
> >
> > >                                      :confirm => 'Are you
> > > sure?',
> >
> > >                                      :method => :delete %>
> >
> > > # with
> >
> > > <%= link_to 'Destroy', @album, :confirm => 'Are you sure?', :method
> > > => :delete %>
> >
> > > And I added in the following into my routes.rb file
> >
> > > ActionController::Routing::Routes.draw do |map|
> > >  map.resources :albums
> > >   map.connect '/public/destroy/:id', :controller => 'public', :action
> > > => 'destroy'    ~#  New line added
> >
> > >  # The priority is based upon order of creation: first created ->
> > > highest priority.
> >
> > >  # Sample of regular route:
> > >  #   map.connect 'products/:id', :controller => 'catalog', :action =>
> > > 'view'
> > >  # Keep in mind you can assign values other than :controller
> > > and :action
> >
> > >  # Sample of named route:
> > >  #   map.purchase 'products/:id/purchase', :controller =>
> > > 'catalog', :action => 'purchase'
> > >  # This route can be invoked with purchase_url(:id => product.id)
> >
> > >  # Sample resource route (maps HTTP verbs to controller actions
> > > automatically):
> > >  #   map.resources :products
> >
> > >  # Sample resource route with options:
> > >  #   map.resources :products, :member => { :short => :get, :toggle
> > > => :post }, :collection => { :sold => :get }
> >
> > >  # Sample resource route with sub-resources:
> > >  #   map.resources :products, :has_many =>
> > > [ :comments, :sales ], :has_one => :seller
> >
> > >  # Sample resource route with more complex sub-resources
> > >  #   map.resources :products do |products|
> > >  #     products.resources :comments
> > >  #     products.resources :sales, :collection => { :recent => :get }
> > >  #   end
> >
> > >  # Sample resource route within a namespace:
> > >  #   map.namespace :admin do |admin|
> > >  #     # Directs /admin/products/* to Admin::ProductsController (app/
> > > controllers/admin/products_controller.rb)
> > >  #     admin.resources :products
> > >  #   end
> >
> > >  # You can have the root of your site routed with map.root -- just
> > > remember to delete public/index.html.
> > >   map.root :controller => "albums"
> >
> > >  # See how all your routes lay out with "rake routes"
> >
> > >  # Install the default routes as the lowest priority.
> > >  map.connect ':controller/:action/:id'
> > >  map.connect ':controller/:action/:id.:format'
> > > end
> >
> > > However it seems to be working but when I do confirm to delete it
> > > redirects me to another action by default being  :controller =>
> > > "albums" and this is set in my routes.rb file like so
> >
> > >  # You can have the root of your site routed with map.root -- just
> > > remember to delete public/index.html.
> > >   map.root :controller => "albums"
> >
> > > How can I amend this so it can redirect it to my action I want it to
> > > go to?
> >
> > > I have copied in my Controller
> >
> > > class PublicController < ApplicationController
> >
> > >  def album_list
> > >    @albums = Album.find_by_sql('SELECT * FROM albums
> > >    WHERE release_date <= \'2006-11-10\'AND artist LIKE \'%Tupac%\'
> > >    ORDER BY release_date ASC ;')
> > >  end
> >
> > >  def alt_album_list
> > >    release_date = '2006-11-10'
> > >    artist = ''
> > >    @albums = Album.find(:all,
> > >   :conditions => ["release_date <= ? AND artist LIKE ?",release_date,
> > > '%' + artist +'%'],
> > >   :order => 'title ASC',
> > >   :limit => 25)
> > >     render(:action => 'album_list')
> >
> > >  end
> >
> > >     def show_album
> > >    release_date = '2006-11-10'
> > >    artist = 'Tupac'
> > >    @album = Album.find(:first,
> > >   :conditions => ["release_date <= ? AND artist LIKE ?",release_date,
> > > '%' + artist +'%'],
> > >   :order => 'title ASC')
> >
> > > end
> >
> > >    def list
> > >      @albums = Album.find(:all)
> > >      render(:action => 'album_list')
> > >     end
> >
> > >     def show
> > >     @album = Album.find(params['id'])
> > >     render(:action => 'show_album')
> > >    end
> >
> > >    def new
> > >      @album = Album.new
> > >    end
> >
> > >    def create
> > >      @album = Album.new(params[:album])
> > >      if @album.save
> > >       redirect_to(:action =>'list')
> > >       else
> > >      render(:action => 'new')
> > >    end
> > >  end
> >
> > >    def edit
> > >       @album = Album.find(params[:id])
> > >      end
> >
> > >    def update
> > >       @album = Album.find(params[:id])
> > >       if @album.update_attributes(params[:album])
> > >       redirect_to(:action =>'list')
> > >       else
> > >      render(:action => 'new')
> > >     end
> >
> > >      def destroy
> > >        @album = Album.find(params['id'])
> > >        @album.destroy
> > >        redirect_to(:action =>'list')
> > >      end
> >
> > >    end
> > > end
> >
> > > Do you have any ideas on why this is?
> >
> > > Thanks
> >
> > > Keith
> >
> > > On Oct 19, 10:20 pm, "raul parolari" <[EMAIL PROTECTED]> wrote:
> > > > Hi, Keith
> >
> > > >    you missed my second email (sent immediately after ther first)
> where I
> > > > warned about the parenthesys that needed to be moved. Or, better,
> remove
> > > the
> > > > parenthesys, and just write:
> >
> > > > <%= link_to  'Destroy', {:action => 'destroy', id => @album.id},
> >
> > > >                                       :confirm => 'Are you
> > > > sure?',
> > > >                                       :method => :delete %>
> >
> > > > This SHOULD work, without changing anything in the routes.rb file.
> > > However,
> > > > allow me to point this important point:
> >
> > > > a) you have the routes.rb configured for REST, but you are not using
> the
> > > > Rest style Urls.
> >
> > > > b) You could delete the line map.resources :albums, if for some
> reason
> > > you
> > > > do not want the RESTful Urls, as at a certain moment there will be
> > > > confusion; or perhaps invert the order of the rules in routes.rb, as
> > > > suggested by the forum post (although I would delete, for more
> clarity).
> >
> > > > On the other hand,  if you wanted to to begin use the Rest routes
> > > (standard
> > > > in Rails since 2007), you would just need to do:
> >
> > > > # replace the lines for delete with:
> > > > <%= link_to "Destroy",    project_path(@album),
> > > >                       *:*confirm => 'Are you sure?', :method =>
> :delete
> > > %>
> >
> > > > # replace the line
> > > > <%= link_to('Edit', :action => 'edit', :id => @album.id ) %>
> > > > # with:
> > > > <%= link_to "Edit",   edit_album_path(@album) %>
> >
> > > > But if you are inserting custom actions (like 'alt_album_list') you
> may
> > > want
> > > > to postpone moving to Rest for the moment. I just showed the above to
> let
> > > > you know.
> >
> > > > > ..."Ruby For Rails" by David A Black which is really helpful. I
> would
> > > also
> >
> > > > like recommend "Agile Web Development..."
> >
> > > > Yes, David Black book is great for Ruby; the AWDWR is great for
> Rails.
> >
> > > > One note: my updated advice for a person seriously interested in Ruby
> > > would
> > > > be:
> >
> > > > a) first, David Black's book mentioned above, as introduction to Ruby
> >
> > > > b) then,  "The Ruby Programming Language", by David Flanagan (with
> > > > contributions from Matz). Not only it shows 1.8, but also 1.9 (in a
> very
> > > > natural way, without confusion). An extraordinary book.
> >
> > > > Raul
> >
> > > > On Sun, Oct 19, 2008 at 1:17 PM, <[EMAIL PROTECTED]> wrote:
> >
> > > > > Hi Raul,
> >
> > > > > Thanks very much for getting back to me. I took your previously
> advise
> > > > > on the book that you recommended "Ruby For Rails" by David A Black
> > > > > which is really helpful. I would also like recommend "Aglie Web
> > > > > Development with Rails"  by Dave Thomas this book is also great if
> you
> > > > > are new to rails.
> >
> > > > > Well Raul I tried the following in my view,
> >
> > > > >      <% if @album != nil -%>
> > > > >         ID:     <%= @album.id %><br/>
> > > > >         Title:  <%= @album.title %> <br/>
> > > > >         Artist: <%= @album.artist %><br/>
> > > > >         Genre:  <%= @album.genre  %><br/>
> > > > >      <%  else -%>
> > > > >         No
> >
> > ...
> >
> > read more ยป- Hide quoted text -
> >
> > - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to