Code Monkey home page Code Monkey logo

rails-sdk's Introduction

CI

rails-sdk

A Rails Integration for Transloadit's file uploading and encoding service

Intro

Transloadit is a service that helps you handle file uploads, resize, crop and watermark your images, make GIFs, transcode your videos, extract thumbnails, generate audio waveforms, and so much more. In short, Transloadit is the Swiss Army Knife for your files.

This is a Rails SDK to make it easy to talk to the Transloadit REST API.

This gem provides browser integration. If you're looking to integrate Transloadit from your own serverside Ruby code checkout the ruby-sdk.

Install

$ gem install transloadit-rails

or add the transloadit-rails Gem to your Rails project's Gemfile and update your bundle.

$ echo "gem 'transloadit-rails'" >> Gemfile
$ bundle install

After installation you need to run the transloadit:install generator to complete the setup.

$ rails g transloadit:install

Configuration

Edit config/transloadit.yml. It has an auth section for your transloadit credentials and a templates section to define or refer to existing templates. It is highly recommended to enable authentication and signing for the upload forms.

auth:
  key     : 'TRANSLOADIT_KEY'
  secret  : 'TRANSLOADIT_SECRET' # optional, but highly recommended
  duration: 1800      # 30 minute validity period for signed upload forms

templates:
  # template identified by template_id
  s3_store: 'YOUR_TEMPLATE_ID'

  # template defined inline
  image_resize:
    steps:
      resize:
        robot : '/image/resize'
        width : 320
        height: 200

Configuration by Environment

The transloadit configurations can be further broken up by environment tags to match the environments used by the application (i.e. development, test, production).

Please note, the environment tags must match the application's environments exactly in order to be used.

development:
  auth:
    key     : 'TRANSLOADIT_KEY'
    ...

  templates:
    s3_store: 'YOUR_TEMPLATE_ID'
    ...

production:
  auth:
    key     : 'TRANSLOADIT_KEY'
    ...

  templates:
    s3_store: 'YOUR_TEMPLATE_ID'
    ...

Usage

Refer to the Templates (which you have set in the config) with the transloadit helper.

<%= form_for :upload, :html => { :id => 'upload' } do |form| %>
  <%= transloadit :s3_store %>
  <%= form.label      :file, 'File to upload' %>
  <%= form.file_field :file %>
  <%= form.submit %>
<% end %>

<%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %>
<%= transloadit_jquerify :upload %>

This requires jQuery, and loads the Transloadit jQuery plugin. Be sure to exclude the <%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %> tag if you already have jQuery loaded.

JavaScript also ensures your form is encoded as multipart/form-data.

If you want to use the automatic transloadit parameter decoding, you have to include the Transloadit::Rails::ParamsDecoder module into your controller

class YourController
  include Transloadit::Rails::ParamsDecoder
end

That way the param[:transloadit] is automatically decoded for you, if it exists.

Note: Since it's still very young, the Transloadit Rails SDK does not include batteries for it yet, but if you're looking for a jQuery-less integration, check out Uppy, our next-gen file uploader for the web.

Tutorial

In this tutorial, you are going to learn how to use transloadit in a freshly setup rails project.

If you haven't already done so, go ahead and install Rails.

$ gem install rails

With rails installed, let's create a new app called 'my_app'.

$ rails new my_app
$ cd my_app

In order to use transloadit in this app, we need to add the gem to our Gemfile and bundle things up.

$ echo "gem 'transloadit-rails'" >> Gemfile
$ bundle install

With that in place, it's time to generate our transloadit configuration, as well as a basic UploadsController and a dummy Upload model.

$ rails g transloadit:install
$ rails g controller uploads new create
$ rails g model upload
$ rake  db:migrate

The controller generator we just executed has probably put two GET routes into your config/routes.rb. We don't want those, so lets go ahead an overwrite them with this.

MyApp::Application.routes.draw do
  resources :uploads
end

Next we need to configure our config/transloadit.yml file. For this tutorial, just put in your credentials, and define an image resize step as indicated below:

auth:
  key     : '4d2e...'
  secret  : '8ad1...'
  duration: 1800      # 30 minute validity period for signed upload forms

templates:
  image_resize:
    steps:
      resize:
        robot : '/image/resize'
        format: 'jpg'
        width : 320
        height: 200

Note that we encourage you to enable authentication in your Transloadit Account and put your secret into the config/transloadit.yml to have your requests signed.

Alright, time to create our upload form. In order to do that, please open app/views/uploads/new.html.erb, and put the following code in:

<%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js' %>

<h1>Upload an image</h1>
<%= form_for Upload.new, :html => { :id => 'upload' } do |form| %>
  <%= transloadit :image_resize %>
  <%= form.label      :file, 'File to upload' %>
  <%= form.file_field :file %>
  <%= form.submit %>
<% end %>

<%= transloadit_jquerify :upload, :wait => true %>

With this in place, we can modify the app/views/uploads/create.html.erb view to render the uploaded and resized image:

<h1>Resized upload image</h1>
<%= image_tag params[:transloadit][:results][:resize].first[:url] %>

In order to use the transloadit params in your controller and views you have to include the ParamsDecoder into your controller. Let's do that for our UploadsController.

Open up app/controllers/uploads_controller.rb and adapt it like that:

class UploadsController < ApplicationController
  include Transloadit::Rails::ParamsDecoder

  def new
  end

  def create
  end

end

That's it. If you've followed the steps closely, you should now be able to try your first upload. Don't forget do start your rails server first:

$ rails server

Then go to http://localhost:3000/uploads/new, and upload an image. If you did everything right, you should see the uploaded and resized file as soon as the upload finishes.

Example

An example rails application following the tutorial above can be found in the examples directory.

Testing

RSpec request specs

If you want to test your file uploads without relying on the network (a good idea to keep them fast and lean) you can include some request spec helpers to allow you to easily populate the transloadit_params and params[:transloadit] in your actions.

First, in your spec/spec_helper.rb :

require 'transloadit/rspec/helpers'

Now, in your request spec :

# NOTE: It's important that you don't use :js => true, otherwise your
#       test will actually hit out using AJAX, making your test dependent on the
#       network.
it "can upload data files", :js => false do
  attach_file 'upload_file', Rails.root.join('spec', 'asset', 'example.pdf')

  # UploadsController should be replaced with the actual controller
  # you're expecting to POST to when the upload is done
  stub_transloadit!(UploadsController, example_json)

  click_button 'Submit'
end

def example_json
  "{ ... JSON content from a real POST ... }"
end

Compatibility

At a minimum, this gem should work on MRI 2.3.0, 2.2.0, 2.1.0, Rubinius, and JRuby. It may also work on older ruby versions, but support for those Rubies is not guaranteed. If it doesn't work on one of the officially supported Rubies, please file a bug report. Compatibility patches for other Rubies are welcome.

Support for EOL'd Ruby 1.9.x and Ruby 2.0 has been dropped, please use version 1.2.0 if you need support for older Ruby versions.

Testing against these versions is performed automatically by GitHub Actions.

Support IE6 or jQuery < 1.9

If you have to support IE6 and use a jQuery version below 1.9, you have to change the jquery_sdk_version in the config to 'v1.0.0':

production:
  jquery_sdk_version: 'v1.0.0'
  auth:
    ...

License

MIT, see LICENSE

rails-sdk's People

Contributors

avokhmin avatar einzige avatar felixge avatar ifedapoolarewaju avatar juliangruber avatar kiloreux avatar kvz avatar levent avatar matthiasjakel avatar nqst avatar olleolleolle avatar rmehner avatar samullen avatar scudco avatar stouset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails-sdk's Issues

Options not working because to_json makes everything a string

In Issue #3 you state you can pass arguments correctly. However, if I want to add a callback function such as :onResult => "my_function() { alert('do stuff') }", the resulting javascript ends up looking like:

"onResult": "my_function() { alert('do stuff') }"

onResult() is a string (rather than a function) and thus, not actually executed. It seems this happens because you parse the options using to_json, which would convert any Javascript code into a string rather than pass it straight through. Am I missing something here? Is there a better way to do this using your gem?

Switch to GitHub Actions

Since Travis isn't usable for open source anymore.

When we are done, we should also update the badge at https://transloadit.com/docs/#sdks by adding this frontmatter to the rails-sdk integration file:

ghactions_workflow: Rails SDK CI # assuming that becomes the github actions workflow name

notify_url usage

on Rails 3.2.8
Im trying to use notify_url

#config/transloadit.yml
auth:
  key     : ...
  secret  : ...
  duration: 1800 # 30 minute validity period for signed upload forms

notify_url: http://...../callback

templates:
  image_video: ...

But, the output generated by <%= transloadit :image_video %> doesn't include notify_url param

Sorry, it was just an undocumented use case, in the view:

<%= transloadit :image_video, :notify_url=>'http://someurl' %>

works

Integrate with Paperclip

Paperclip is pretty ubiquitous. It'd be nice to integrate support with it. There will likely be multiple use-cases:

  1. Upload to S3 with transloadit
    a. needs to extend paperclip with a transloadit_id in the path
    b. needs to add migrations for transloadit_id
  2. Retrieve upload from transloadit, upload to S3 in paperclip

undefined method `transloadit'

Going from the example in the README:

<%= form_tag 'http://api2.transloadit.com/assemblies', :html => { :id => 'upload' } do |form| %>
  <%= transloadit :s3_store %>
  <%= form.label      :file, 'File to upload' %>
  <%= form.file_field :file %>
  <%= form.submit %>
<% end %>
<%= transloadit_jquerify :upload %>

I get undefined method 'transloadit' for #<#<Class:0x000000011aadc8>:0x00000005ebd840>.

alert: "Could not find input[name=params] in your form" on submission

I followed the tutorial but can't get the form to submit without getting the aforementioned alert. After I click "ok", Transloadit quickly throws INVALID_FORM_DATA: bad form data, cannot parse.

My app is using Rails 4.1.4 and jquery-rails 2.1.4.

Here's my form:

= form_for @profile, url: community_add_photo_path(@profile), html: {id: 'photo_form'} do |f|
  = render 'shared/error_messages', object: f.object
  = transloadit :profile_photo
  = hidden_field_tag 'transloadit_template', 'profile_photo'

  %table.list
    %tr
      %td.faded.label Photo Filename
      %td= f.file_field :photo, required: true
    %tr
      %td
      %td= f.submit 'Upload'

= transloadit_jquerify :photo_form, wait: true

And my transloadit.yml file:

development:
  jquery_sdk_version: 'latest'
  auth:
    key:      'key'
    secret:   'secret'
    duration: 1800 # 30 minute validity period for signed upload forms

  templates:
    profile_photo:
      steps:
        resize:
          height: 256
          resize_strategy: 'fillcrop'
          robot: '/image/resize'
          width: 256
        store:
          bucket: 'bucket-name'
          key: 'key'
          path: 'temp/${assembly.id}/${file.name}'
          robot: '/s3/store'
          secret: 'secret'

Any suggestions? Thanks!

Rails-sdk compatible with rails 2.3

My app is using ruby 1.8.7 and rails 2.3.5. Does the current version of rails-sdk support rails 2.3? If it is not, could you give me a link of older version which compatible with rails 2.3?

Ability to vary expiration time on forms

Currently these helpers result in a form that is valid for 5 minutes. Thats quite rough.

Case: User comes to form. Spends 10 minutes on finding 5 photos to upload. Hits upload -> suddenly the upload is invalid because form was valid only 5 minutes.

I'd need the follow to work:

<%= transloadit :upload_basics, {:auth => [:expires => 1.hour.from_now]} %>

Easiest would be to change view_helper to change the hash auth params before signing it. More clearlier fix would be to change how ruby-sdk work and change this one accordingly.

Lazy config loading

Users should be able to edit their transloadit config without having to restart the server during development.

Better error message when config loading fails

Something went wrong when loading my config, and I got:

NoMethodError in Uploads#index

Showing /Users/felix/Desktop/transloadit-test/app/views/uploads/index.html.erb where line #2 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]

Extracted source (around line #2):

1: <%= form_for :thing, :html => { :id => 'upload' } do |form| %>
2:   <%= form.transloadit :my_template %>
3:   <%= form.file_field :file, 'File to upload' %>
4: <% end %>
5: 

Rails.root: /Users/felix/Desktop/transloadit-test

Turning this into a more helpful message would be great.

Publish new gem version

Hi,

I just merged #10 from my friend Robin who is using the gem for a very big project. His changes made sense to me so I went ahead, but please feel free to comment.

If things look reasonable, could you please publish a new version of the gem? If there is a way to make it possible for me to do that as well, that'd be great.

--fg

Cant convert a video to mp4 and keep its size

I am trying get a video out as a mp4 and I need to keep the original proportions.

This is my current Template

{
  "steps": {
    "encode": {
      "use": ":original",
      "robot": "/video/encode",
      "ffmpeg_stack": "v2.2.3",
      "result": true,
      "preset": "ipad-high",
      "ffmpeg_params": {
        "s": "-1x-1"
      }
    },
    "thumbnails": {
      "use": ":original",
      "robot": "/video/thumbs"
    },
    "store": {
      "use": "encode",
      "robot": "/s3/store",
      "key": "xxxxxxxxxxx",
      "secret": "xxxxxxxxxxx",
      "bucket": "xxxxxxxxxxx"
    }
  }
}

Add full example

From installing rails to uploading and resizing an image and displaying the results.

example response for an Assembly

A user playing around with the rails example had this to say

The Rails example you have does not include any information about how to save the uploaded file information to the database for later usage. I can see the information can be taken from some params, but to me the documentation seems very confusing there - params[:transloadit][:results][:resize].first[:url] - how does this adapt to different Transloadit templates? How can I get the information on the form itself before submitting it?

A good way to solve this may be to have the example display a formatted JSON tree of the assembly response.

Not working with latest jquery-rails gem

transloadit-rails works great for me using jquery-rails 2.1.3 (which uses JQuery 1.8.2). But it doesn't work with jquery-rails 2.2.1 (JQuery 1.9.1). The symptom is that the form submit doesn't seem to get intercepted anymore - the form gets posted straight to my server.

Let me know if this is jquery-sdk's fault and I'll move this issue over.

Deprecation warning in Rails 3.2

Using this gem with Rails 3.2 results in:

DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future 
releases, simply use Ruby memoization pattern instead. (called from <top (required)>
 at .../config/application.rb:11)

it looks like it should be simple to replace the memoize :configuration call with a bit of @configuration cachery.

Problem with transloadit_jquerify when trying to define callbacks.

Hi,

I tried to call transloadit_jquerify method while defining onError and onCancel callbacks, like this:

<%= transloadit_jquerify :video_form, wait: false, processZeroFiles: false,
  onCancel: "function() { console.log('Entered on cancel'); }",
  onError: "function() { console.log('Entered on error'); }" %>

but it did not work. The generated script was like this:

<script type="text/javascript">
//<![CDATA[

      jQuery(function($) {
        var script = '//assets.transloadit.com/js/jquery.transloadit2-latest.js';

        $.getScript(script, function() {
          $('#video_form')
            .attr('enctype', 'multipart/form-data')
            .transloadit({"wait": false,
"processZeroFiles": false,
"onCancel": function() {console.log('Entered on cancel'); },
"onError": function() { console.log('Entered on error'); }});
        });
      });

//]]>
</script>

I figured out that the problem's with the "onCancel" and "onError" being strings. When I wrote the generated script manually and removed the double quotes it all worked well.

Also there's not much documentation regarding how to use callback functions with transloadit_jquerify. I had to take a look at the code to see how you guys expect callbacks to be provided.

uninitialized constant Transloadit::Rails::ViewHelper

Hello,

I am using Rails 3.1

transloadit-rails gem version 1.0.2

I tried to use the transloadit-rails gem by following the tutorial for rails-sdk. Can anyone help me?

This is the error log

[2011-10-19 15:47:06] ERROR NameError: uninitialized constant Transloadit::Rails::ViewHelper
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/transloadit-rails-1.0.0/lib/transloadit/rails/engine.rb:21:in `block (2 levels) in <class:Engine>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:216:in `<class:Base>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:133:in `<module:ActionView>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_view/base.rb:8:in `<top (required)>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/abstract_controller/view_paths.rb:90:in `view_paths='
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/abstract_controller/view_paths.rb:76:in `prepend_view_path'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/engine.rb:532:in `block (2 levels) in <class:Engine>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `each'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.1/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:234:in `<class:Base>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:171:in `<module:ActionController>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_controller/base.rb:3:in `<top (required)>'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:31:in `ext'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:15:in `match?'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.1.1/lib/action_dispatch/middleware/static.rb:47:in `call'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/engine.rb:456:in `call'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/rack/content_length.rb:16:in `call'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.1.1/lib/rails/rack/log_tailer.rb:14:in `call'
    /Users/weyewe/.rvm/gems/ruby-1.9.2-p180/gems/rack-1.3.5/lib/rack/handler/webrick.rb:59:in `service'
    /Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
    /Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
    /Users/weyewe/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

Hashify JSON response

Transloadit returns a JSON response that should be converted to a Rails-style HashWithIndifferentAccess automatically. Figure out how to do this, and do it.

/file/filter robot

Hi,

I've been trying to make the /file/filter robot work with my rails app and failing.
I haven't found any useful ruby on rails examples in the Transloadit docs.
I would like some help on how to use the /file/filter robot to decline a file larger than 10MB using ruby on rails.

Thank you

max_size doesn't seem to work.

I tried putting max_size in the transloadit.yml file like this:

auth:
  key     : '418...'
  secret  : '660...'
  duration: 1800 # 30 minute validity period for signed upload forms
  max_size: 2097152

templates: ...

I can't get it to work. According to the Authentication page in the docs

You need to use max_size in the hidden params field of your form.

I've tried adding a hidden field in the form named "max_size" but it doesn't work either.

Is there a way to set a maximum file size?

Dynamic fields not working in template

I'm trying to update my transloadit templates to use some more dynamic fields from the html form (Rails, Rackspace cloud files, transloadit_jquerify etc), however the fields object doesn't seem to contain the values I'm passing.

The template is set up like this:

store:
          use: ['optimized']
          robot: '/cloudfiles/store'
          container: *rs_container
          user: *rs_user
          key: *rs_key
          data_center: *rs_data_center
          account_type: *rs_account_type
          path: "images/${fields.item_category}/${file.id}_${file.url_name}"

and my HTML form contains the following:

<%= form_for item, :url => form_url, :html => { :id => 'upload_image' } do |form| %>
  <%= transloadit :image_upload %>
  <%= form.label :file, 'File to upload' %>
  <%= form.file_field :file, :accept => "image/jpg, image/jpeg, image/png" %>
  <%= form.label :name, "Description" %>
  <input type="text" name="name" id="name"/>

  <!-- I have tried both options for creating a hidden field -->
  <%= form.hidden_field 'item_category', :value => item_category %>
  <input type="hidden" name="item_category" id="item_category" value="<%= item_category %>" />

  <%= form.submit 'Upload Image', :id => "submitBtnImage" %>
<% end %>

<%= transloadit_jquerify :upload_image, :wait => true, :processZeroFiles => false %>

But the item_category is always empty or nil, resulting in a file path like images//XXX_file.jpg

Any ideas what I'm doing wrong here?

Helpers javascript/jquery output fails with other libraries

rails-sdk / app / helpers / transloadit_helper.rb file needs fixes. (https://github.com/transloadit/rails-sdk/blob/master/app/helpers/transloadit_helper.rb)

Dollar sign is also used by other libraries, so you can't trust that its reserved for jquery: http://docs.jquery.com/Plugins/Authoring

(Yeah, I'm slowly migrating from prototype to jquery)

transloadit_helper.rb produces following:

$(function() {
CODE INSIDE HERE
});

It should be:

(function($) {
CODE INSIDE HERE
}(jQuery));

So the total helper would be:

def transloadit_jquerify(id, options = {})
    javascript_tag %{
      (function($) {
      var script = '//assets.transloadit.com/js/jquery.transloadit2.js';
      $.getScript(script, function() {
      $('##(id)')
      .attr('enctype', 'multipart/form-data')
      .transloadit({wait: true, fields: true});
      });
      }(jQuery));
    }
end

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.