d01e9f3c3f
closes #69
64 lines
1.2 KiB
Ruby
64 lines
1.2 KiB
Ruby
module ApplicationHelper
|
|
MAX_PAGES = 15
|
|
|
|
def errors_for(object, message=nil)
|
|
html = ""
|
|
unless object.errors.blank?
|
|
html << "<div class=\"flash-error\">\n"
|
|
object.errors.full_messages.each do |error|
|
|
html << error << "<br>"
|
|
end
|
|
html << "</div>\n"
|
|
end
|
|
|
|
raw(html)
|
|
end
|
|
|
|
def time_ago_in_words_label(time, options = {})
|
|
strip_about = options.delete(:strip_about)
|
|
ago = time_ago_in_words(time, options)
|
|
|
|
if strip_about
|
|
ago.gsub!(/^about /, "")
|
|
end
|
|
|
|
raw(label_tag(nil, ago, :title => time.strftime("%F %T %z")))
|
|
end
|
|
|
|
def page_numbers_for_pagination(max, cur)
|
|
if max <= MAX_PAGES
|
|
return (1 .. max).to_a
|
|
end
|
|
|
|
pages = (cur - (MAX_PAGES / 2) + 1 .. cur + (MAX_PAGES / 2) - 1).to_a
|
|
|
|
while pages[0] < 1
|
|
pages.push (pages.last + 1)
|
|
pages.shift
|
|
end
|
|
|
|
while pages.last > max
|
|
if pages[0] > 1
|
|
pages.unshift (pages[0] - 1)
|
|
end
|
|
pages.pop
|
|
end
|
|
|
|
if pages[0] != 1
|
|
if pages[0] != 2
|
|
pages.unshift "..."
|
|
end
|
|
pages.unshift 1
|
|
end
|
|
|
|
if pages.last != max
|
|
if pages.last != max - 1
|
|
pages.push "..."
|
|
end
|
|
pages.push max
|
|
end
|
|
|
|
pages
|
|
end
|
|
end
|