ruby - Dynamic routes with Rails 3 -
i have task develop rails application following model routing.
i need have pagecontroller
, page
model. page urls must /contacts, /shipping, /some_page
.
also need have catalogcontroller
, category
model. categories urls must /laptops, /smartphones/android
.
and productscontroller
, product
model, urls of products must line /laptops/toshiba_sattelite_l605
, /smartphones/android/htc_magic
i understand problem can solved using urls like
/page/shipping
/catalog/smartphones/android
but customer not want see insertion of "/page
" or "/catalog
" in url.
please tell me direction solving problem. sorry bad english.
you'll have write "catch-all" rule:
on routes.rb:
get '*my_precioussss' => 'sauron#one_action_to_rule_them_all'
your precious controller:
class sauroncontroller < applicationcontroller def one_action_to_rule_them_all @element = find_by_slug(params[:my_precioussss]) render @element.kind # product, category, etc end end
then write 1 view each "kind" of element: product.html.erb, category.html.erb, etc.
make sure write find_by_slug
implementation.
you can change one_action_to_rule_them_all
pikachu_i_choose_you
, sauroncontroller
pokemoncontroller
, work too.
Comments
Post a Comment