
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 0.75 KB | hits: 24 | expires: Never
How can I get my URL's to look like www.example.com/1/product/date/price?
Price :belongs_to Products
Product :has_many Prices
def to_param
"#{id}/#{product.name}/#{purchase_date}/#{price}".parameterize
end
http://localhost:3000/prices/8-turkey-bacon-2012-01-16-2-58
http://localhost:3000/8/turkey-bacon/2012-01-16/$2.58
resources :prices do
get ":id/:product_name/:purchase_date/:price" => "prices#show"
get :autocomplete_product_name, :on => :collection
post :create_multiple, :on => :collection
end
require 'uri'
class Price < ActiveRecord::Base
def to_param
URI.encode("/#{id}/#{product.name}/#{purchase_date}/#{price}")
end
end
# in routes.rb
get ":id/:product_name/:purchase_date/:price" => "controller#action"