jamal
March 6, 2007, 7:09pm
1
Hello there,
I’m doing something like “categories” page, I want to do the URLs like
this.
http://domain/category/ [show everything in all categories]
http://domain/category/movies [show only in movies category]
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
jamal
March 6, 2007, 7:52pm
2
On Mar 6, 12:09 pm, Jamal S. [email protected]
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
jamal
March 6, 2007, 8:00pm
3
Okay, thats real awesome
Thats why I keep getting more and more in love with RoR
Amazing framework
jamal
March 6, 2007, 8:01pm
4
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.”