Hello :) I generated model, view and controler for products database table using scaffold I try to change controler name from product to admin but I can''t :( (I didn''t know how to specifi diferent controler name when use scaffold) I controllers/s_controller.rb to controllers/admin_controller.rb view/products directory to view admin directory layout/products.html.erb to layout/admin.html.erb and make some modifications but i can''t do it because there are some strange thinks view\products\index.html <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 %></td> what are these edit_product_path functions? And why edit link is something like <td><a href="/products/1/edit">Edit</a></td> and not <td><a href="/products/edit/1">Edit</a></td> when i try to make /admin/1/edit request I get an error that I have not action 1, it works only with /admin/edit/1 in products controler it works both ways: /products/1/edit and /products/edit/1/ Can you help me, pls :) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If I have to short my question it is: view/products/index.html.erb <h1>Listing products</h1> <table> <tr> <th>Title</th> <th>Description</th> <th>Image url</th> </tr> <% for product in @products %> <tr> <td><%=h product.title %></td> <td><%=h product.description %></td> <td><%=h product.image_url %></td> <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 %></td> </tr> <% end %> </table> <br /> <%= 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 And why both work? ??? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-25 10:29 UTC
Re: Strange (for me) Scaffold source code generated
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> ??? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung 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 fileThank you very much :) Now I understand that I have to learn this: http://guides.rubyonrails.org/routing_outside_in.html -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ju Lian wrote:> Frederick Cheung 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.htmlI 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 %></td> <%= 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 %></td> <%= link_to ''New product'', new_admin_path %> =================================== /view/products/new.hmtl.erb ================================ <h1>New product</h1> <% form_for(@product) do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.label :description %><br /> <%= f.text_area :description %> </p> <p> <%= f.label :image_url %><br /> <%= f.text_field :image_url %> </p> <p> <%= f.submit "Create" %> </p> <% end %> <%= link_to ''Back'', products_path %> =================================== /view/admin/new.hmtl.erb ================================ <h1>New product</h1> <% form_for(@product) do |f| %> <%= f.error_messages %> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.label :description %><br /> <%= f.text_area :description %> </p> <p> <%= f.label :image_url %><br /> <%= f.text_field :image_url %> </p> <p> <%= f.submit "Create" %> </p> <% 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
May be this is the right way (it works) ============ === routes.rb ============ map.resources :products, :as => ''admin'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---