Comments (4)
I wasn't able to reproduce the problem.. The only place where that method is called is within the renderer:
https://github.com/assembler/attachinary/blob/master/lib/assets/javascripts/attachinary.js.coffee#L14
Can you run following code in chrome console and see if there are public_ids?
$('.attachinary-input').eq(0).data('attachinary-bond').files
from attachinary.
When I run that I get:
TypeError: Cannot read property 'files' of undefined
It didn't find any, probably because I don't see any data attributes on the elements named attachinary-bond -- where is that coming from? I'm assuming this error has something to do with a change in Rails between 3.2 and 4.0.0.beta.
Here's the raw HTML of that file uploader in my form (with api keys removed, etc)...maybe this has to do with the html entity encoding of the JSON?
<div class="control-group attachinary optional lead_capture_cobrand_logo">
<label class="attachinary optional control-label" for=
"lead_capture_cobrand_logo">Cobrand logo</label>
<div class="controls">
<input accept="image/png" class="attachinary optional attachinary-input"
data-attachinary="{"accessible":true,"accept":["png"],"single":true,"scope":"cobrand_logo","maximum":1,"singular":"cobrand_logo","plural":"cobrand_logos","files":[{"file":{"id":4,"public_id":"wdfh9dqqx8nxmqvpsn9z","version":"1362446364","format":"png","resource_type":"image","path":"v1362446364/wdfh9dqqx8nxmqvpsn9z.png"}}]}"
data-form-data="{"timestamp":1362488720,"callback":"http://localhost:5000/attachinary/cors","tags":"development_env,attachinary_tmp","signature":"43671c75bac13290c29bfe3xxxxxxxx7458dcf2c","api_key":"345xxxxxxxxx571"}"
data-url="https://api.cloudinary.com/v1_1/hbhhv9rz9/auto/upload" id="lead_capture_cobrand_logo" name="lead_capture[cobrand_logo]" type="file" />
</div>
</div>
Using the inspector, when I change data-attachinary to data-attachinary-bond, your debug console test works and my file object is returned, parsed, etc with a good public_id -- question is why is my attribute called data-attachinary when the Javascript is looking for data-attachinary-bond?
Your help is very appreciated. Also I'll be contributing the Rails4 changes back to the Gem once they are tested and ready.
from attachinary.
Oh and one other detail -- direct-to-s3 uploading works perfectly and saves to the model, etc. It's just rendering the already-uploaded image in the form that is producing this JS error.
from attachinary.
Took a few hours, but I finally figured it out. Appears in Rails4 that as_json returns the "root" by default, which meant each file in the array of files was proceeded by a "file" root instead of just the object itself.
For example, the Javacscript expected the structure to be like this:
[{id: 1, public_id: "xxxxx" ....} , {id: 2, public_id: "xxxxx" ....}]
In Rails4, it was returning:
[{"file": {id: 1, public_id: "xxxxx" ....}) , {"file": {id: 2, public_id: "xxxxx" ....}}]
The fix was to pass the option "root: false" in the as_json method in the file mixin. This change will be included in my Rails4 pull request later this week.
from attachinary.
Related Issues (20)
- Dependency on old version of cloudinary gem HOT 4
- The attachment files options may be serialized in the wrong way
- Problem implementing has_attachments HOT 1
- destroy_file callback not invoked HOT 4
- File instances break on serialization w/ active model serializers
- Validate presence error message
- undefined method `has_attachment' HOT 3
- Rails 5.1 HOT 9
- Using with administrate gem HOT 1
- limit min and max file size upload HOT 2
- rake attachinary:install:migrations -> Index table names are too long HOT 2
- ArgumentError Exception: too few arguments
- Destroy attachinary
- Chunked video upload HOT 1
- Attachinary::File::ActiveRecord_Associations_CollectionProxy:0x007fa5fbada388
- Issue with `process_input` function with Rails 5 Parameters
- Add custom filed to attachinary
- Handling video files better
- CORS endpoint echoes unsafe JSON / Potential XSS
- attachinary_file_field as required
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 attachinary.