make 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/make/form.rb +20 -21
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bcc508e38182d88b21adc2c6e071d361fd41591
|
4
|
+
data.tar.gz: a157388fabe661e035b6bd0801a46456979bc094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96901320b5bdd5a306039d8a7a8a01725405c4890d679ec4f73ba9da13182710395b58bcf943e825604564f0f89dfec1e002673dca75aa7c550778842e739058
|
7
|
+
data.tar.gz: 8a67532d917365db39a2ed53a5722f899e7b8e8657c911e992d58232ff7a1adc512b78340d43bec9d5a2242c94666391b270001a04cb86346010d271573659d3
|
data/lib/make/form.rb
CHANGED
@@ -66,36 +66,32 @@ class Form
|
|
66
66
|
def select column, array, assoc = false
|
67
67
|
columnName = column.titleize
|
68
68
|
input = "\n\t<label>" + columnName + "\n\t</label>\n\t<select name=\"" + @modelName + "[" + column + "]\">"
|
69
|
-
|
70
|
-
array.each do |id|
|
71
|
-
val = column[0...-3].capitalize.constantize.find(id).attributes.values[1]
|
72
|
-
input += "\n\t\t\t<option value=\"" + id.to_s + "\">" + val.to_s + "</option>"
|
73
|
-
end
|
74
|
-
else #if no associations exist for array
|
75
|
-
array.each do |item|
|
76
|
-
input += "\n\t\t\t<option value=\"" + item.to_s + "\">" + item.to_s + "</option>"
|
77
|
-
end
|
78
|
-
end
|
69
|
+
input += "\n\t\t\t<option value=\"" + item.to_s + "\">" + item.to_s + "</option>"
|
79
70
|
@potential_keys_to_ignore.push(column)
|
80
71
|
input += "\n\t</select>"
|
81
72
|
@formMiddle.push(input)
|
82
73
|
return self
|
83
74
|
end
|
84
75
|
# Similar to select, but association assumed and specific associated column name can be selected
|
85
|
-
def assoc column,
|
76
|
+
def assoc column, assoc_column, assoc_model=nil
|
77
|
+
# titleize column
|
86
78
|
columnName = column.titleize
|
79
|
+
# Create for input
|
87
80
|
input = "\n\t<label>" + columnName + "\n\t</label>\n\t<select name=\"" + @modelName + "[" + column + "]\">"
|
88
|
-
assocModel
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
81
|
+
# Remove _id and take the assocModel unless assocModel exists
|
82
|
+
if assoc_model
|
83
|
+
assoc_model = assoc_model.capitalize.constantize
|
84
|
+
else
|
85
|
+
assoc_model = column[0...-3].capitalize.constantize
|
94
86
|
end
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
87
|
+
# Keep track of how many records exist in assocModel
|
88
|
+
total = assoc_model.distinct.count('id')
|
89
|
+
# run a while loop for as many records there are
|
90
|
+
counter = 1
|
91
|
+
while counter <= total do
|
92
|
+
val = assoc_model.find(counter).attributes[assoc_column]
|
93
|
+
input += "\n\t\t\t<option value=\"" + counter.to_s + "\">" + val.to_s + "</option>"
|
94
|
+
counter+= 1
|
99
95
|
end
|
100
96
|
input += "\n\t</select>"
|
101
97
|
@potential_keys_to_ignore.push(column)
|
@@ -129,6 +125,9 @@ class Form
|
|
129
125
|
input = "\n\t<label>Confirm Password</label>\n\t<input type=\"password\" name=\"" + @modelName + "[password_confirmation]\">"
|
130
126
|
@formMiddle.push(input)
|
131
127
|
end
|
128
|
+
elsif column.include? 'date'
|
129
|
+
input = "\n\t<label>"+column.titleize+"</label>\n\t<input type=\"date\" name=\"" + @modelName + "[" + column + "]\">"
|
130
|
+
@formMiddle.push(input)
|
132
131
|
else
|
133
132
|
input = "\n\t<label>" + column.titleize + "\n\t</label>\n\t<input type=\"text\" name=\"" + @modelName + "[" + column + "]\">"
|
134
133
|
@formMiddle.push(input)
|