Module: RailsInfo::FormHelper

Defined in:
app/helpers/rails_info/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#rails_info_field(name, options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/rails_info/form_helper.rb', line 2

def rails_info_field(name, options = {})
  error = @filter.errors[name]
  hint = options.delete(:hint)
  
   :div, class: 'control-group' + (error ? ' error' : '') do
    content = []
    
    content << label_tag("filter[#{name}]", name.humanize, class: 'control-label')
    
    content << (:div, class: 'controls') do
      controls = []
       
      unless block_given? 
        controls << text_field_tag("filter[#{name}]", @filter.send(name), options)
      end
      
      controls << (:p, hint, class: 'help-block') if hint
      controls << (:span, error, class: 'help-inline') if error
      
      controls = controls.join(' ')
      
      if block_given?
        yield(name, controls)
      else
        raw controls
      end
    end
    
    raw content.join(' ')
  end
end

#short_path(path, setting) ⇒ Object



34
35
36
37
38
39
40
# File 'app/helpers/rails_info/form_helper.rb', line 34

def short_path(path, setting)
  begin
    path.gsub(setting[:paths].select{|part| path.match(part) }.first, '')
  rescue TypeError
    raise [path, setting[:paths]].inspect
  end
end