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
on 2007-03-06 20:09
on 2007-03-06 20:52
On Mar 6, 12:09 pm, Jamal S. <email@example.com> 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 softiesonrails.com
on 2007-03-06 21:00
Okay, thats real awesome :D Thats why I keep getting more and more in love with RoR :D Amazing framework :D
on 2007-03-06 21:01
Jamal S. wrote: > Okay, thats real awesome :D > > Thats why I keep getting more and more in love with RoR :D > > Amazing framework :D And of course "Thanks For Your Help Jeff C."