Rails - pretty URI instead of Restful URI
in View
<tr onclick="window.location.href = '<%= url_for :controller => "products", :action 开发者_高级运维=> "index", :product => release.product_name, :version => release.version %>'" >
In controller
release = Release.find_ver_rel(params[:product], params[:version])
respond_to do |format|
format.html { render :template => 'releases/overview' }
end
It produces URI: /products?product=Atlas&version=0.2
How to get "pretty uri" like /products/product/Atlas/version/0.2
?
In your routes file config/routes.rb
put
match '/products/product/:name/version/:version' => 'product#index', :as => :something
This way, you can either pass variables directly into something_path(:name => 'Name')
, or fetch it from params[:name]
.
精彩评论