thanks, I solve my problem, you have given good explanation on ROUTER along width tutorial link.
On 10/04/2011, radhames brito <[email protected]> wrote: > I see, you are confused, adding resources does not create a new action, i > creates 7 default actions, which are > > index, show , new , create , edit , update and destroy, these are called > restful action because they obey the REST (Resource State Transfer )design > in which wach of this actions is aided by the http header to tell the server > in what state the resourse will be access. Look, here i ordered : http > method, url , what it maps to, and the rails helper. > > Get => "/users" => "users#index" helper => users_path > > this tells the server that the http method is get , and you want to trigger > the index action of the users controller, which will bring back a > collection that is why you dont specify an id, on the other hand, rails > create a helper method, you can use in you app. > > Get => "/users/:id" => "users#show" helper => user_path(:id) > > this tells the server that the method is get, you want to trigger the show > action of the users controller and in this case you want a single element, > that is why you need to specify an id, so the server know what element you > want, note that the helper method that rails create is singular. > > now look at the ones that change the state of the resource. > > Put => "/users/:id" => "users#update" > Post=>"/users" => "users#create" > > ok, as you can see the urls are the sames as index and show, but in this > case they are mapped to different actions, the difference is made by the > http method, that is how the server know what action to trigger. Since > almost every application users the common index, show , new , create , edit > , update and destroy, rails has a method that creates all of them on one > pass: resources. Passing map.resources :users create this > > users GET /users(.:format) > {:action=>"index", :controller=>"users"} > user GET /users/:id(.:format) > {:action=>"show", :controller=>"users"} > edit_user GET /users/:id(.:format) > {:action=>"edit", :controller=>"users"} > new_user GET /users(.:format) {:action=>"new", > :controller=>"users"} > users POST /users(.:format) > {:action=>"create", :controller=>"users"} > user PUT /users/:id(.:format) > {:action=>"update", :controller=>"users"} > DELETE /users/:id(.:format) > {:action=>"destroy", :controller=>"users"} > > So instead of having to speficy all that for every resource( which sometimes > is a table in your db ) you just pass > > map.resources :users > > and rails will create the whole bunch. > > > In your file you are passing login to resource, and create this > > logins GET /logins(.:format) > {:action=>"index", :controller=>"logins"} > POST /logins(.:format) > {:action=>"create", :controller=>"logins"} > new_login GET /logins/new(.:format) {:action=>"new", > :controller=>"logins"} > edit_login GET /logins/:id/edit(.:format) > {:action=>"edit", :controller=>"logins"} > login GET /logins/:id(.:format) > {:action=>"show", :controller=>"logins"} > PUT /logins/:id(.:format) > {:action=>"update", :controller=>"logins"} > DELETE /logins/:id(.:format) > {:action=>"destroy", :controller=>"logins"} > > im sure that is not quite what you thought you were doing, because you did > it 5 times, rails goes by each and override each and at the end will only > show you the result of the last one, but you are only overriding the some > thing over and over again, you have never added a new action after the first > one. > > You really only have this > > map.resources :logins > map.resources :signups > map.resources :orders > map.resources :stories > > this is creating 28 routes for you. > > the error you are getting > > "Couldn't find Login with ID=again" > > happens when you try to access a routes that requires an id, like edit, > update, show, or delete and then you are not passing any id. > > put "/users" > > this will cause that error since put maps to update and you have to pass an > id to tell the server what you want, like this > > > put "/users/34" > > read more about rails routing at the rials guider for rails 2.3.8 > > > http://guides.rubyonrails.org/v2.3.8/routing.html > > -- > 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. > > -- 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.

