Router error!

Hi everyone,

I am adding a new action(again) in exiting scaffold generated
controller(logins). there is router problem.

Couldn’t find Login with ID=again

i have rails 2.3.8
ruby 1.8.6

what code will i add in my route.rb and where???

please help me.

thanks in advance

you have to post your routes.rb file.

On Sat, Apr 9, 2011 at 2:33 PM, radhames brito [email protected]
wrote:

thanks for write back,

i am mailing my route.erb file.

ActionController::Routing::Routes.draw do |map|

map.resources :logins

map.resources :logins

map.resources :logins

map.resources :logins

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :logins

map.resources :signups

map.resources :signups

map.resources :signups

map.resources :orders

map.resources :stories

map.resources :stories

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 => “welcome”

See how all your routes lay out with “rake routes”

Install the default routes as the lowest priority.

Note: These default routes make all actions in every controller

accessible via GET requests. You should

consider removing or commenting them out if you’re using named

routes and resources.
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end

thanks,

I solve my problem, you have given good explanation on ROUTER along
width tutorial link.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs