Module: ApplicationHelper

Defined in:
app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#label_tooltip(object_name, method, content_or_options = nil, options = nil) ⇒ Object

render the label and the toolip beside it (passed in the options as :tip)



38
39
40
41
42
43
# File 'app/helpers/application_helper.rb', line 38

def label_tooltip(object_name, method, content_or_options = nil, options = nil)
  label object_name, method do
    concat(content_or_options + " ") if !content_or_options.nil? && !content_or_options.blank?
    concat(tooltip_tag(options[:tip])) if !options.nil? && options.has_key?(:tip) && !options[:tip].blank?
  end
end

Generate an <a> link tag that submits a Rails form, instead of having to always use inputs or buttons.



47
48
49
# File 'app/helpers/application_helper.rb', line 47

def link_to_submit(*args, &block)
  link_to_function (block_given? ? capture(&block) : args[0]), "$(this).closest('form').submit()", args.extract_options!
end

#render_partial_if(partial, default = nil, locals = {}) ⇒ Object

Render the partial at the specified path if it exists within the lookup_context, otherwise render the partial specified in default if it exists. Locals are passed along accordingly.



21
22
23
24
25
26
27
# File 'app/helpers/application_helper.rb', line 21

def render_partial_if(partial, default=nil, locals={})
  if lookup_context.exists?(partial, [], true)
    render :partial => partial, :locals => locals
  elsif !default.blank?
    render :partial => default, :locals => locals
  end
end

#tooltip_tag(tip, text = nil, options = nil) ⇒ Object

render tooltip



30
31
32
33
34
35
# File 'app/helpers/application_helper.rb', line 30

def tooltip_tag(tip, text = nil, options = nil)
  results = []
  results << (:span, text, options) + " " if !text.nil? && !text.blank?
  results << (:i, nil, { :class => "icon-question-sign muted tooltip-basic", :data => { :tooltip_text => tip } })
  results.join.html_safe
end

#user_leads_a_group?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'app/helpers/application_helper.rb', line 8

def user_leads_a_group?
  current_user.memberships.each do |m|
    if m.level == Membership::LEVELS[:leader]
      return true
    end
  end
  return false
end

#yield_for_title(default) ⇒ Object

Generate page titles.



4
5
6
# File 'app/helpers/application_helper.rb', line 4

def yield_for_title(default)
  content_for?(:title) ? content_for(:title) : default
end