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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 6, 12:09 pm, Jamal Soueidan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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) ?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Okay, thats real awesome :D Thats why I keep getting more and more in love with RoR :D Amazing framework :D -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan wrote:> Okay, thats real awesome :D > > Thats why I keep getting more and more in love with RoR :D > > Amazing framework :DAnd of course "Thanks For Your Help Jeff Cohen" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---