Change the way links are displayed in menus in front-end

This commit is contained in:
Christophe Vilayphiou committed 2012-05-14 21:43:10 +08:00
1 parent 6c83b3f9ae
commit 8fcb8ef8de
3 files changed
+16 -4

No files matched your search

+1 -1
View File
@@ -21,7 +21,7 @@ class PagesController < ApplicationController
when 'Page'
render_page
when 'Link'
redirect_to "http://#{@item[:url]}"
redirect_to @item[:url]
end
else
render :file => "#{Rails.root}/public/404.html", :status => :not_found
+11 -1
View File
@@ -2,10 +2,20 @@ class Link < Item
field :url
validates_presence_of :url
validates :url, :presence => true, :format => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
before_validation :add_http
def link
ApplicationController.helpers.link_to(self.name, self.url)
end
protected
def add_http
unless self.url[/^http?s:\/\//]
self.url = 'http://' + self.url
end
end
end