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?
Asked
Active
Viewed 294 times
1

Teddy
- 579
- 1
- 4
- 17
-
Do you want to keep the existing routes, or do you want to send to "tags"? Or both? – Jesse Wolgamott Aug 02 '10 at 21:39
-
Not quite clear what you're asking. You want to receive this: "/tags/page?pid=microsoft-interview-questions" with "page?pid=microsoft-interview-questions" to be the :id parameter? – mark Aug 02 '10 at 21:39
-
Sorry for not being clear, I would like `/page?pid=microsoft-interview-questions` to go to :controller => tags, :action => show for the tag titled microsoft. – Teddy Aug 02 '10 at 21:44
-
It looks like you could deploy rails on Google App Engine... http://stackoverflow.com/questions/3278745/ruby-on-rails-app-on-google-app-engine – ckrailo Aug 02 '10 at 22:14
2 Answers
1
something like this should work (in routes.rb):
map.connect '/page?pid=:number', :controller => 'tags', :action => 'show'
see routes reference
-
The only problem with that is that I don't know how to parse out the '-interview-questions' after the tag name. – Teddy Aug 02 '10 at 21:44
1
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
- 10,316
- 6
- 37
- 58
-
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 Aug 02 '10 at 22:44