# How to create Urls =\> Controller

**URL:** <https://www.ruby-forum.com/t/how-to-create-urls-controller/87902>\
**Category:** Rails\
**Created:** [March 6, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-create-urls-controller/87902 "2007-03-06T19:09:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [March 6, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/how-to-create-urls-controller/87902/1 "2007-03-06T19:09:24Z")

</div>

Hello there,

I’m doing something like “categories” page, I want to do the URLs like  
this.

[http://domain/category/](http://domain/category/) [show everything in all categories]  
[http://domain/category/movies](http://domain/category/movies) [show only in movies category]  
[http://domain/category/music](http://domain/category/music) [etc]

In PHP I used .htaccess to do that, but I wonder how to do this in RoR,  
should I also use .htaccess, or I can use the category controller to  
handle all the actions in one method (index) ?

Thanks for any help 🙂

Regards,  
Jamal

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [March 6, 2007, 7:52pm UTC](https://www.ruby-forum.com/t/how-to-create-urls-controller/87902/2 "2007-03-06T19:52:11Z")

</div>

On Mar 6, 12:09 pm, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> should I also use .htaccess, or I can use the category controller to  
> handle all the actions in one method (index) ?

In Rails you use the routes.rb file to map incoming URLs to your  
controllers and actions.

map.connect '/category/:filter/, :controller =\> ‘categories’, :action  
=\> ‘index’

In your CategoriesController class, you can now inspect  
params[:filter] to see what (if anything) was specified:

class CatagoriesController \< ApplicationController

def index  
if params[:filter]  
@items = Item.find\_all\_by\_type(params[:filter)]  
else  
@items = Item.find :all  
end  
end

end

and then your index.rhtml can display the @items array.

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [March 6, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/how-to-create-urls-controller/87902/3 "2007-03-06T20:00:49Z")

</div>

Okay, thats real awesome 😃

Thats why I keep getting more and more in love with RoR 😃

Amazing framework 😃

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [March 6, 2007, 8:01pm UTC](https://www.ruby-forum.com/t/how-to-create-urls-controller/87902/4 "2007-03-06T20:01:29Z")

</div>

Jamal S. wrote:

> Okay, thats real awesome 😃
> 
> Thats why I keep getting more and more in love with RoR 😃
> 
> Amazing framework 😃

And of course “Thanks For Your Help Jeff C.”
