I am changing my site over from Google App Engine to rails and I would like to keep my place in google search. Currently my site uses a URL /page?pid=microsoft-interview-questions
to access the Microsoft subsection of interview questions. How would I create a route that can send this to '/tags/:id'
where :id would be microsoft in this case?
views:
51answers:
2
+1
A:
something like this should work (in routes.rb):
map.connect '/page?pid=:number', :controller => 'tags', :action => 'show'
see routes reference
joshc
2010-08-02 21:37:36
The only problem with that is that I don't know how to parse out the '-interview-questions' after the tag name.
Teddy
2010-08-02 21:44:48
+1
A:
In addition to josh's answer I'll put this here for formatting:
# your controller
def show
@subject = Subject.find my_stripped_id
private
def my_stripped_id
params[:id].sub(/-interview-questions/, '')
end
mark
2010-08-02 22:10:20
This takes care of the logic part of distilling the id. It seems though, that because of the ? it is passing the parameter as pid instead of id
Teddy
2010-08-02 22:44:06