tap/app/helpers/application_helper.rb

62 lines
1.5 KiB
Ruby
Raw Normal View History

2014-12-09 13:10:36 +01:00
require 'digest/md5'
2014-11-06 14:46:59 +01:00
module ApplicationHelper
2014-12-09 13:10:36 +01:00
def get_color(user)
2014-12-10 05:13:17 +01:00
Digest::MD5.hexdigest(user.nickname)[0..5]
2014-12-09 13:10:36 +01:00
end
def get_color_style(user)
2014-12-10 05:13:17 +01:00
"background-color: \#"+ get_color(user) +";"
2014-12-09 13:10:36 +01:00
end
2014-12-09 14:39:27 +01:00
def euro(f)
"#{number_with_precision f, precision: 2}"
end
# Form helpers
def form_errors(object)
render partial: "form_errors", locals: {object: object}
end
def form_text_field(f, tag)
render partial: "form_text_field", locals: {f: f, tag: tag}
end
def form_password_field(f, tag)
render partial: "form_password_field", locals: {f: f, tag: tag}
end
def form_text_area(f, tag)
render partial: "form_text_area", locals: {f: f, tag: tag}
end
def form_fancy_text_area(f, tag)
render partial: "form_fancy_text_area", locals: {f: f, tag: tag}
end
def form_email_field(f, tag)
render partial: "form_email_field", locals: {f: f, tag: tag}
end
def form_date_field(f, tag, id, value)
render partial: "form_date_field", locals: {f: f, tag: tag, id: id, value: value}
end
def form_number_field(f, tag)
render partial: "form_number_field", locals: {f: f, tag: tag}
end
def form_collection_select(f, *args)
# This line enable passing optional arguments such as include_blank to the
# partial. If nothing is passed, an empty options hash is appended.
args << {} if args.length < 5
render partial: "form_collection_select", locals: {f: f, args: args}
end
def form_check_box(f, tag)
render partial: "form_check_box", locals: {f: f, tag: tag}
end
2014-12-09 13:10:36 +01:00
2014-11-06 14:46:59 +01:00
end