Permalink
Browse files

update for forbidden_action and to have distance_of_time_for handle s…

…trings
  • Loading branch information...
1 parent 8f88093 commit feed6c6ba608f6f4022b07632bf16e1f1e6d8095 @UnderpantsGnome committed Aug 29, 2008
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/rails_extensions.rb
View
@@ -20,6 +20,12 @@ class << self
def simple_action(*actions)
actions.each {|action| class_eval("def #{action}; end")}
end
+
+ def forbidden_action(*actions)
+ actions.each {|action|
+ class_eval("def #{action}; render :nothing => true, :status => :forbidden; end")
+ }
+ end
end
end
end
@@ -52,7 +58,14 @@ def public_file_path(file)
end
def distance_of_time_for(obj, method)
- "<span title=\"#{obj.send(method).localtime}\">#{distance_of_time_in_words_to_now(obj.send(method).localtime)}</span>"
+ begin
+ date_time = obj.send(method)
+ date_time = Time.parse(date_time) if date_time.is_a?(String)
+ from_ago = date_time < Time.new ? 'ago' : 'from now'
+ "<span title=\"#{date_time.localtime}\">#{distance_of_time_in_words_to_now(date_time.localtime)} #{from_ago}</span>"
+ rescue
+ "<span style=\"display:none\">object does not respond to #{method}</span>"
+ end
end
def back_link(text='Back', *args)

0 comments on commit feed6c6

Please sign in to comment.