Module: Conjoin::FormBuilder
- Defined in:
- lib/conjoin/inputs/date.rb,
lib/conjoin/inputs/file.rb,
lib/conjoin/inputs/text.rb,
lib/conjoin/inputs/time.rb,
lib/conjoin/inputs/year.rb,
lib/conjoin/form_builder.rb,
lib/conjoin/inputs/radio.rb,
lib/conjoin/inputs/state.rb,
lib/conjoin/inputs/hidden.rb,
lib/conjoin/inputs/select.rb,
lib/conjoin/inputs/string.rb,
lib/conjoin/inputs/boolean.rb,
lib/conjoin/inputs/decimal.rb,
lib/conjoin/inputs/display.rb,
lib/conjoin/inputs/integer.rb,
lib/conjoin/inputs/checkbox.rb,
lib/conjoin/inputs/datetime.rb,
lib/conjoin/inputs/password.rb
Defined Under Namespace
Classes: BooleanInput, CheckboxInput, DateInput, DatetimeInput, DecimalInput, DisplayInput, Fields, FileInput, HiddenInput, Input, IntegerInput, PasswordInput, RadioInput, SelectInput, StateInput, StringInput, TextInput, TimeInput, YearInput
Constant Summary
collapse
- INPUTS =
[
:boolean , :checkbox , :date , :decimal , :file , :hidden ,
:integer , :password , :radio , :select , :state , :string ,
:display , :datetime , :time , :year , :text
]
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.setup(app) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/conjoin/form_builder.rb', line 11
def self.setup app
require 'conjoin/mab'
app.plugin Conjoin::Csrf
INPUTS.each do |input|
require_relative "inputs/#{input}"
end
Dir["#{app.root}/app/inputs/**/*.rb"].each { |rb| require rb }
end
|
Instance Method Details
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/conjoin/form_builder.rb', line 23
def form_for record, options = {}, &block
raise ArgumentError, "Missing block" unless block_given?
if as = options.delete(:as)
model_name = as
elsif record.is_form?
model_name = record.class.model_name.to_s.gsub(/\w+::/, '').gsub(/Form$/, '').underscore
else
model_name = record.class.model_name.singular
end
fields = Fields.new self, [model_name], record, block
form_options = {
class: 'form-horizontal',
role: 'form',
method: 'post',
novalidate: 'true',
remote: true,
action: options.delete(:url) || "/" + record.class.model_name.plural
}.merge! options
if form_options.delete(:remote)
form_options['data-remote'] = 'true'
end
mab do
form form_options do
input type: 'hidden', name: '_method', value: (record.id ? 'patch' : 'post')
text! csrf_tag
text! fields.render
end
end
end
|