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

file_field helper raises an exception if attribute does not match an active storage attachment #43698

Closed
brenogazzola opened this issue Nov 23, 2021 · 1 comment
Assignees

Comments

@brenogazzola
Copy link
Contributor

brenogazzola commented Nov 23, 2021

Steps to reproduce

model Gallery
  has_many_attached :images
end
<%= form_with model: Gallery.new do |form| %>
  <%= form.file_field :image, direct_upload: true %>
<% end %>
ActionView::Template::Error (undefined method `options' for nil:NilClass):

In this case the attachment is called images, but we passed the atribute image. The bug was introduced in PR #38957, which added per attachment service. The problem happens because this line:

attachment_reflection = options[:object].class.reflect_on_attachment(name)

... ends with attachment_reflection = nil and then this line:

service_name = attachment_reflection.options[:service_name] || ActiveStorage::Blob.service.name

... causes the nil exception.

Expected behavior

The page is rendered using the default service

Actual behavior

An exception is raised.

System configuration

Rails version: 193289d
Ruby version: 3.0.2

cc: @DmitryTsepelev @gmcgibbon

@brenogazzola
Copy link
Contributor Author

Fixed by #44287

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants