Hi,
Could anyone help with this one.
I want to have two routes into my news stories for the show view, one
by ID and the other by the URL of the story which is stored in the db.
I have two routes setup …
map.connect ‘itcontractormortgagenews/:id’, :controller =>
‘posts’, :action => ‘show’
map.connect ‘itcontractormortgagenews/:url’, :controller =>
‘posts’, :action => ‘show’
and I have edited my show method in the controller to …
if params[:id].to_i > 0
@post = Post.find(params[:id])
else
@post = Post.find_by_sql(“select * from posts where URL = '” +
params[:url] + “’”).first
end
The mapping by URL works fine but by ID not. I’m sure there is a
better way to do this.
Thanks
Richard.