module ApplicationHelper def getdatetime(registration, field) if registration.send(field.to_sym).kind_of?(String) DateTime.parse(registration.send(field.to_sym)).strftime("%d %b %H:%M") if registration.send(field.to_sym) else registration.send(field.to_sym).strftime("%d %b %H:%M") if registration.send(field.to_sym) end end def getdate(var) if var.kind_of?(String) DateTime.parse(var).strftime("%a, %d %b") else var.strftime("%a, %d %b") end end def add_association_link(association_name, form_builder, div_class, html_options = {}) link_to_add_association "Add " + association_name.to_s.singularize, form_builder, div_class, html_options.merge(:class => "assoc btn btn-success") end def remove_association_link(association_name, form_builder) link_to_remove_association("Remove " + association_name.to_s.singularize, form_builder, :class => "assoc btn btn-danger") + tag(:hr) end def dynamic_association(association_name, title, form_builder, options = {}) render "shared/dynamic_association", :association_name => association_name, :title => title, :f => form_builder, :hint => options[:hint] end def has_role?(current_user, role) if current_user.nil? return false end return !!current_user.role?(role.to_s.camelize) end # Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to() def redirect_back_or_to(options = {}, response_status = {}) if request.env["HTTP_REFERER"] redirect_to(:back) else redirect_to(options, response_status) end end # TODO Output better html def format_comments(comment, padding = 0) result = "" result += "