Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symbol support to the collection option from the association builder #1705

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/simple_form/inputs/collection_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def input_options
def collection
@collection ||= begin
collection = options.delete(:collection) || self.class.boolean_collection
collection = reflection.klass.send(collection) if collection.is_a?(Symbol)
collection.respond_to?(:call) ? collection.call : collection.to_a
end
end
Expand Down
6 changes: 6 additions & 0 deletions test/form_builder/association_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def with_association_for(object, *args)
assert_equal 3, calls
end

test 'builder association accepts symbols to use as scopes' do
simple_form_for @user do |f|
f.association :company, collection: :all
end
end

test 'builder association marks input as required based on both association and attribute' do
swap SimpleForm, required_by_default: false do
with_association_for @validating_user, :company, collection: []
Expand Down