Created
August 30, 2011 03:04
-
-
Save softwaregravy/1180070 to your computer and use it in GitHub Desktop.
Finding the Object in the Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# my_value_array :text | |
class MyModel < AciveRecord::Base | |
serialize :my_value_array, Array | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @my_model do |f| %> | |
<%= f.text_field :my_value_array %> | |
# produces <input type="text" id="my_model_my_value_array" name="my_model[my_value_array]" value="#{@my_model.my_value_array}" /> | |
<%= f.submit %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for @my_model do |f| %> | |
# existing values in the array | |
<% if f.object.my_value_array.present? %> | |
<% f.object.my_value_array.each do |v| %> | |
<input type="text" id="my_model_my_value_array" name="my_model[my_value_array][]" value="#{v}" /> | |
<% end %> | |
<% end %> | |
# space for new values for the array | |
<input type="text" id="my_model_my_value_array" name="my_model[my_value_array][]" /> | |
<input type="text" id="my_model_my_value_array" name="my_model[my_value_array][]" /> | |
# could be clever here to dynamically add these to allow adding more then 2 elements at a time | |
<%= f.submit %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment