Assert_redirected help

assert_redirected_to category_path(assigns(:category))

this line for example…when i use it in my code

def test_should_create_category
login_as :admin
assert_difference Category, :count, 1 do
post :create, :category => { }
end
assert_redirected_to category_path(assigns(:category))
end

i get an error sayin
undefined method category_path

where is this defined??

where should i define it?

Hi Sanjana D.

where is this defined??
where should i define it?

  Have you defined the routes for category in config/routes.rb

Sijo

Sijo k g wrote:

Hi Sanjana D.

where is this defined??
where should i define it?

  Have you defined the routes for category in config/routes.rb

Sijo

i have defined the routes.rb file as

map.root :controller => “site”, :action => “home”
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
map.resources :categories, :controller => “categories”,:action =>
“create”

or i have tried it as in another way

ActionController::Routing::Routes.draw do |map|
map.resources :categories
end
map.root :controller => “site”, :action => “home”
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

when i try either of this now…i m not getting a undefined category_path
anymore…but now i m getting a different error…

Error:
test_should_create_category(CategoriesControllerTest):
ActionController::RoutingError: category_url failed to generate from
{:action=>“show”, :controller=>“categories”, :id=>nil}, expected:
{:action=>“show”, :controller=>“categories”}, diff: {:id=>nil}
(eval):16:in category_path' test/functional/categories_controller_test.rb:305:intest_should_create_category’

rake routes
(in /home/sanjana/Desktop/categ)

                   / 

{:action=>“edit”, :controller=>“categories”}
categories GET /categories(.:format)
{:action=>“index”, :controller=>“categories”}
POST /categories(.:format)
{:action=>“create”, :controller=>“categories”}
new_category GET /categories/new(.:format) {:action=>“new”,
:controller=>“categories”}
edit_category GET /categories/:id/edit(.:format) {:action=>“edit”,
:controller=>“categories”}
category GET /categories/:id(.:format) {:action=>“show”,
:controller=>“categories”}
PUT /categories/:id(.:format)
{:action=>“update”, :controller=>“categories”}
DELETE /categories/:id(.:format)
{:action=>“destroy”, :controller=>“categories”}
root /
{:action=>“home”, :controller=>“site”}
/:controller/:action/:id
/:controller/:action/:id(.:format)

Hi Sanjana

ActionController::Routing::Routes.draw do |map|
map.resources :categories
end
map.root :controller => “site”, :action => “home”
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

It is

ActionController::Routing::Routes.draw do |map|
map.root :controller => “site”, :action => “home”
map.resources :categories
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end

map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’

This can be avoided if you define all ypur routes in routes.r properly

ActionController::RoutingError: category_url failed to generate from
{:action=>“show”, :controller=>“categories”, :id=>nil}, expected:
{:action=>“show”, :controller=>“categories”}, diff: {:id=>nil}

This shows the show action does not getting the id..From your first 

post, is
assigns(:category) has value?

Sijo