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

Make BelongsTo fields nullable #312

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [#251] [FEATURE] Raise a helpful error when an attribute is missing from
`ATTRIBUTE_TYPES`
* [#298] [FEATURE] Support ActiveRecord model I18n translations
* [#312] [FEATURE] Add a `nil` option to `belongs_to` form fields
* [#231] [UI] Fix layout issue on show page where a long label next to an empty
value would cause following fields on the page to be mis-aligned.
* [#309] [UI] Fix layout issue in datetime pickers where months and years
Expand Down
2 changes: 1 addition & 1 deletion lib/administrate/fields/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def permitted_attribute
end

def associated_resource_options
candidate_resources.map do |resource|
[nil] + candidate_resources.map do |resource|
[display_candidate_resource(resource), resource.id]
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/fields/belongs_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
candidates = field.associated_resource_options

expect(Foo).to have_received(:all)
expect(candidates).to eq([])
expect(candidates).to eq([nil])
ensure
remove_constants :Foo
end
Expand Down