Module: Dorsale::FormHelper

Included in:
AllHelpers
Defined in:
app/helpers/dorsale/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#form_buttons(opts = {}) ⇒ Object



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
# File 'app/helpers/dorsale/form_helper.rb', line 3

def form_buttons(opts = {})
 back_url = opts[:back_url]
 back_url = url_for(:back).html_safe if back_url.blank?
 back_url = URI(back_url).path       if back_url.include?("://")

  if opts[:obj].present?
    if opts[:obj].new_record?
      submit_action = :create
    else
      submit_action = :update
    end
  else
    submit_action = :save
  end

  ("div", class: "actions") do
    submit = (:button, type: :submit, class: "btn btn-sm btn-success") do
      (:span, class: "fa fa-save") {} + " " + t("actions.#{submit_action}")
    end

    cancel = ("a", href: back_url, class: "btn btn-primary btn-sm") do
      (:span, class: "fa fa-times"){} + " " + t("actions.cancel")
    end

    cancel = "" if back_url == false

    submit + cancel
  end
end

#horizontal_form_for(obj, opts = {}, &block) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/dorsale/form_helper.rb', line 33

def horizontal_form_for(obj, opts={}, &block)
  opts = {
    :wrapper => "horizontal_form",
    :html => {
      :class => "form-horizontal"
    }
  }.deep_merge(opts)

  simple_form_for(obj, opts, &block)
end

#search_form(opts = {}) ⇒ Object



44
45
46
47
48
# File 'app/helpers/dorsale/form_helper.rb', line 44

def search_form(opts = {})
  action = opts.delete(:action) || request.fullpath

  render "dorsale/search/form", action: action
end