Comments (6)
This is weird. Is your class an ActiveRecord?
This is how the method is implemented:
https://github.com/stitchfix/stitches/blob/master/lib/stitches/errors.rb#L71
what it's doing is basically iterating over all the active record errors on your object and, if the field with an error itself is an active record, get those errors.
it could be that the way it does this isn't quite right. The code:
stitches/lib/stitches/errors.rb
Line 73 in c457ed6
is assuming that if the field's value responds to errors
, it's therefore an ActiveRecord and thus errors
will return an active record errors object, not a hash.
It sounds like in your case, errors
on either your object, or an object your object references has an errors
method that returns a hash and not an active record errors object.
from stitches.
The class is inheriting from ApplicationRecord
class Medium < ApplicationRecord
...
validate :ojbect_size_valid
...
def ojbect_size_valid
errors.add(:object, 'should be less than or equal to 5MB for images') if object_file_size > 5.megabytes && image_type?
errors.add(:object, 'should be less than or equal to 15MB for gifs and videos') if object_file_size > 15.megabytes && (gif_type? || video_type?)
end
private
def image_type?
object_content_type =~ /jpeg/ || object_content_type =~ /jpg/ || object_content_type =~ /png/
end
def gif_type?
object_content_type =~ /gif/
end
def video_type?
object_content_type =~ /video/
end
def pdf_type?
object_content_type =~ /pdf/
end
end
The AppilcationRecord
is just inheriting from ActiveRecord
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
from stitches.
Hm. My guess is that the code is detecting that .object
returns a value that responds to errors
but that errors
is actually a hash. What is the type of object
on this class?
from stitches.
Whoops meant to leave that in:
has_attached_file :object, styles: ->(f) { f.instance.check_file_type }
object
is a paperclip attachment to the medium
from stitches.
https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L83
Stitches assumes if the object responds to #errors
it's an active record. This is probably a bug in stitches.
To solve your immediate problem, you could inline the implementation of from_active_record
and fix it so it doesn't break. I probably can't look into a fix today, but maybe could this week. I think it's as simple as checking if errors
is an ActiveModel::Errors
from stitches.
Believe I figured it out...
So the "field" isn't really object
, but instead object_file_size
Paperclip basically yields a wrapper to the various metadata about the object
from stitches.
Related Issues (20)
- Use failure_message instead of failure_message_for_should HOT 1
- Header override HOT 1
- Failure message on fresh install and rspec run. HOT 5
- Find a way to run the generator in a test HOT 1
- ApiClients should be de-activatable HOT 3
- Set up CI HOT 2
- Remove Unused Middleware HOT 2
- Error for have_api_error always says 422
- Consider integrating easymon for monitoring HOT 1
- Gem release tasks HOT 1
- Generate migrations through Rails not template files HOT 1
- License missing. MIT? HOT 4
- White-list "complex" route HOT 1
- Root route always unauthorized HOT 1
- Version is missing in the response headers HOT 10
- Alternative white lisiting method because `configuration.allowlist_regexp` is error prone HOT 6
- Deprecation warning in Rails 6 HOT 1
- Uninitialized constant Api::V1 in debug HOT 3
- Use expect instead of should syntax for all specs given by generator HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stitches.