Skip to content

Commit

Permalink
Added link redirection based on the short url given
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Vergult committed Aug 18, 2010
1 parent 1834461 commit dc63cde
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ def create
redirect_to root_path
end
end

def redirect
begin
@link = Link.find(params[:link_reference].alphadecimal)
rescue
flash[:error] = "Not a valid url"
redirect_to root_path
else
redirect_to @link.address
end
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
root :to => "home#index"

resources :links

match ":link_reference" => "links#redirect"
# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down

0 comments on commit dc63cde

Please sign in to comment.