# Assert\_redirected help

**URL:** <https://www.ruby-forum.com/t/assert-redirected-help/179907>\
**Category:** Rails\
**Created:** [December 7, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/assert-redirected-help/179907 "2009-12-07T21:11:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanjanad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@sanjanad](https://www.ruby-forum.com/u/sanjanad)\
**Post date:** [December 7, 2009, 9:11pm UTC](https://www.ruby-forum.com/t/assert-redirected-help/179907/1 "2009-12-07T21:11:43Z")

</div>

```
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?

---

<div class="post-metadata">

**Author:** ![sanjanad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@sanjanad](https://www.ruby-forum.com/u/sanjanad)\
**Post date:** [December 8, 2009, 5:20am UTC](https://www.ruby-forum.com/t/assert-redirected-help/179907/2 "2009-12-08T05:20:07Z")

</div>

Hi Sanjana D.

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

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

```

Sijo

---

<div class="post-metadata">

**Author:** ![sanjanad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@sanjanad](https://www.ruby-forum.com/u/sanjanad)\
**Post date:** [December 11, 2009, 9:58pm UTC](https://www.ruby-forum.com/t/assert-redirected-help/179907/3 "2009-12-11T21:58:42Z")

</div>

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:in`test\_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)

---

<div class="post-metadata">

**Author:** ![sanjanad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c67d28/32.png) [@sanjanad](https://www.ruby-forum.com/u/sanjanad)\
**Post date:** [December 12, 2009, 3:35am UTC](https://www.ruby-forum.com/t/assert-redirected-help/179907/4 "2009-12-12T03:35:25Z")

</div>

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
