lib/formtastic/helpers/inputs_helper.rb in formtastic-3.1.5 vs lib/formtastic/helpers/inputs_helper.rb in formtastic-4.0.0.rc1
- old
+ new
@@ -213,11 +213,11 @@
# <% semantic_form_for @post do |form| %>
# <%= f.inputs :name => 'Write something:' do %>
# <%= f.input :title ... %>
# <%= f.input :body ... %>
# <% end %>
- # <%= f.inputs do :name => 'Advanced options:' do %>
+ # <%= f.inputs :name => 'Advanced options:' do %>
# <%= f.input :user ... %>
# <%= f.input :categories ... %>
# <% end %>
# <% end %>
#
@@ -308,11 +308,11 @@
protected
def default_columns_for_object
cols = association_columns(:belongs_to)
cols += content_columns
- cols -= Formtastic::FormBuilder.skipped_columns
+ cols -= skipped_columns
cols.compact
end
def fieldset_contents_from_column_list(columns)
columns.collect do |method|
@@ -348,15 +348,24 @@
else
[]
end
end
+ # Collects all foreign key columns
+ def foreign_key_columns # @private
+ if @object.present? && @object.class.respond_to?(:reflect_on_all_associations)
+ @object.class.reflect_on_all_associations(:belongs_to).map(&:foreign_key)
+ else
+ []
+ end
+ end
+
# Collects content columns (non-relation columns) for the current form object class.
def content_columns # @private
# TODO: NameError is raised by Inflector.constantize. Consider checking if it exists instead.
begin klass = model_name.constantize; rescue NameError; return [] end
return [] unless klass.respond_to?(:content_columns)
- klass.content_columns.collect { |c| c.name.to_sym }.compact
+ klass.content_columns.collect { |c| c.name.to_sym }.compact - foreign_key_columns
end
# Deals with :for option when it's supplied to inputs methods. Additional
# options to be passed down to :for should be supplied using :for_options
# key.