Hi, i''ve just 2 questions. The first is about the url, now i can see a page with site/products/1 but how can i do something prettier like site/products/1-my-first-product (with a product named: "My first product") ? What have i to change and how? The second question is about ajax, i''ve a select with some categories with more levels (e.g. A, A1, A2, B, B1, B11, B12, and so on...A1 and A2 are children of A, as B11 and B12 are for B1 which is for B). How can i do something that when i select the category A, it''ll load the 2 children A1 and A2 ? Now i''ve set that when i send the form it load the children and render again the form, select one of them and send the form again, it''s quit too much for just a send of a product. So, how can i load them with ajax? Thanks a lot :) -- 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 -~----------~----~----~----~------~----~------~--~---
anyone? :( -- 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 -~----------~----~----~----~------~----~------~--~---
Up :''( -- 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 -~----------~----~----~----~------~----~------~--~---
the way one would normally do this is to add a "permalink" column to the database. for your purpose, we''d use and after_create, but it seems inefficient to do 2 database queries class Product after_create :set_permalink def set_permalink hyphenated_name = self.name.downcase.gsub(/\s+/, "-") self.permalink = "#{self.id}-#{hyphenated_name}" end end then in your routes.rb map.permalink("products/:permalink", :controller => "products" ) and in your product_controller def show @product = if params[:permalink] Product.find_by_permalink(params[:permalink]) else Product.find(params[:id]) end end Mix Mix wrote:> Hi, i''ve just 2 questions. The first is about the url, now i can see a > page with site/products/1 but how can i do something prettier like > site/products/1-my-first-product (with a product named: "My first > product") ? > What have i to change and how?-- 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 -~----------~----~----~----~------~----~------~--~---
you''d have to save that aswell def set_permalink hyphenated_name = self.name.downcase.gsub(/\s+/, "-") self.update_attribute(:permalink, "#{self.id}-#{hyphenated_name}") end> class Product > after_create :set_permalink > > def set_permalink > hyphenated_name = self.name.downcase.gsub(/\s+/, "-") > self.permalink = "#{self.id}-#{hyphenated_name}" > end > end-- 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 -~----------~----~----~----~------~----~------~--~---
Matthew Rudy wrote:> ...thanks, i''ll try :) what about the ajax call? :( -- 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 -~----------~----~----~----~------~----~------~--~---
anyone know for the ajax call? :( -- 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 -~----------~----~----~----~------~----~------~--~---
Not too long ago, I wrote a popular blog post about getting pretty 1-this-is-a-pretty-url style using Rails'' to_param method. See http://www.jroller.com/obie/entry/seo_optimization_of_urls_in On 7/21/07, Mix Mix <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > anyone know for the ajax call? :( > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Obie Fernandez http://jroller.com/obie/ Pre-order my book The Rails Way today! http://www.amazon.com/dp/0321445619 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---