Giter Club home page Giter Club logo

Comments (4)

assembler avatar assembler commented on July 17, 2024

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.

rochers avatar rochers commented on July 17, 2024

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="{&quot;accessible&quot;:true,&quot;accept&quot;:[&quot;png&quot;],&quot;single&quot;:true,&quot;scope&quot;:&quot;cobrand_logo&quot;,&quot;maximum&quot;:1,&quot;singular&quot;:&quot;cobrand_logo&quot;,&quot;plural&quot;:&quot;cobrand_logos&quot;,&quot;files&quot;:[{&quot;file&quot;:{&quot;id&quot;:4,&quot;public_id&quot;:&quot;wdfh9dqqx8nxmqvpsn9z&quot;,&quot;version&quot;:&quot;1362446364&quot;,&quot;format&quot;:&quot;png&quot;,&quot;resource_type&quot;:&quot;image&quot;,&quot;path&quot;:&quot;v1362446364/wdfh9dqqx8nxmqvpsn9z.png&quot;}}]}"
        data-form-data="{&quot;timestamp&quot;:1362488720,&quot;callback&quot;:&quot;http://localhost:5000/attachinary/cors&quot;,&quot;tags&quot;:&quot;development_env,attachinary_tmp&quot;,&quot;signature&quot;:&quot;43671c75bac13290c29bfe3xxxxxxxx7458dcf2c&quot;,&quot;api_key&quot;:&quot;345xxxxxxxxx571&quot;}"
        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.

rochers avatar rochers commented on July 17, 2024

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.

rochers avatar rochers commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.