Ju Lian wrote:
Frederick C. wrote:
On 25 Nov 2008, at 10:11, Ju Lian wrote:
<%= link_to ‘New product’, new_product_path %>
what is this function edit_product_path and why the result is
/1/edit and not /edit/1
Short answer: restful routing. When you declare a route for products
in routes.rb this add a bunch of named routes, so new_product_path is
the url which gives you the path where the new product form is,
edit_product_path(some_product) is the url for editing some_product
etc…
And why both work?
because you still have the old controller/action/id routes in your
routes.rb file
Thank you very much 
Now I understand that I have to learn this:
http://guides.rubyonrails.org/routing_outside_in.html
I still can’t change controller name from products to admin
=============
=== routes.rb
ActionController::Routing::Routes.draw do |map|
map.resources :products
map.resources :admin
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end
May be controler name must be ‘admins’ ?
Some of helpers functions doesn’t work for me 
=================================
=== /view/products/index.hmtl.erb
<td><%= link_to 'Show', product %></td>
<td><%= link_to 'Edit', edit_product_path(product) %></td>
<td><%= link_to 'Destroy', product, :confirm => 'Are you sure?',
:method => :delete %>
<%= link_to ‘New product’, new_product_path %>
become:
=== /view/admin/index.hmtl.erb
<td><%= link_to 'Show', admin_path(:id => product.id) %></td>
<td><%= link_to 'Edit', edit_admin_path(:id => product.id) %></td>
<td><%= link_to 'Destroy', admin_path(:id => product.id), :confirm
=> ‘Are you sure?’, :method => :delete %>
<%= link_to ‘New product’, new_admin_path %>
=================================
=== /view/products/new.hmtl.erb
New product
<% form_for(@product) do |f| %>
<%= f.error_messages %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.label :image_url %>
<%= f.text_field :image_url %>
<%= f.submit "Create" %>
<% end %>
<%= link_to ‘Back’, products_path %>
=================================
=== /view/admin/new.hmtl.erb
New product
<% form_for(@product) do |f| %>
<%= f.error_messages %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.label :image_url %>
<%= f.text_field :image_url %>
<%= f.submit "Create" %>
<% end %>
<%= link_to ‘Back’, admin_path %>
1-st The form submits to product controller instead of new admin
controller
2-nd admin_path or admins_path in the last row give me an error
What I am doing wrong?
Is there some reason not to change controller name from products to
admin?