transloadit-rails 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -21
- data/lib/transloadit/rails.rb +6 -2
- data/lib/transloadit/rails/controller_extensions.rb +18 -0
- data/lib/transloadit/rails/version.rb +4 -4
- metadata +6 -3
data/README.md
CHANGED
@@ -9,7 +9,7 @@ you to automate uploading files through the Transloadit REST API.
|
|
9
9
|
|
10
10
|
## Install
|
11
11
|
|
12
|
-
gem install transloadit
|
12
|
+
gem install transloadit-rails
|
13
13
|
|
14
14
|
## Getting started
|
15
15
|
|
@@ -65,32 +65,32 @@ It also uses JavaScript to ensure your form is encoded as `multipart/form-data`.
|
|
65
65
|
In this tutorial, you are going to learn how to use transloadit in a freshly
|
66
66
|
setup rails project.
|
67
67
|
|
68
|
-
If you haven't already done so, go ahead
|
69
|
-
transloadit gem:
|
68
|
+
If you haven't already done so, go ahead and install Rails.
|
70
69
|
|
71
70
|
$ gem install rails
|
72
|
-
$ gem install transloadit
|
73
71
|
|
74
|
-
With rails installed, let's create a new app called 'my_app'
|
72
|
+
With rails installed, let's create a new app called 'my_app'.
|
75
73
|
|
76
74
|
$ rails new my_app
|
77
75
|
$ cd my_app
|
78
76
|
|
79
77
|
In order to use transloadit in this app, we need to add the gem to our Gemfile
|
80
|
-
and bundle things up
|
78
|
+
and bundle things up.
|
81
79
|
|
82
80
|
$ echo "gem 'transloadit-rails'" >> Gemfile
|
83
81
|
$ bundle install
|
84
82
|
|
85
83
|
With that in place, it's time to generate our transloadit configuration, as
|
86
|
-
well as a basic UploadsController
|
84
|
+
well as a basic UploadsController and a dummy Upload model.
|
87
85
|
|
88
|
-
$ rails
|
89
|
-
$ rails
|
86
|
+
$ rails g transloadit:install
|
87
|
+
$ rails g controller uploads new create
|
88
|
+
$ rails g model upload
|
89
|
+
$ rails db:migrate
|
90
90
|
|
91
91
|
The controller generator we just executed has probably put two GET routes into
|
92
92
|
your `config/routes.rb`. We don't want those, so lets go ahead an overwrite
|
93
|
-
them with this
|
93
|
+
them with this.
|
94
94
|
|
95
95
|
MyApp::Application.routes.draw do
|
96
96
|
resources :uploads
|
@@ -119,7 +119,7 @@ Alright, time to create our upload form. In order to do that, please open
|
|
119
119
|
<%= javascript_include_tag '//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js' %>
|
120
120
|
|
121
121
|
<h1>Upload an image</h1>
|
122
|
-
<%= form_for
|
122
|
+
<%= form_for Upload.new, :html => { :id => 'upload' } do |form| %>
|
123
123
|
<%= form.transloadit :image_resize %>
|
124
124
|
<%= form.label :file, 'File to upload' %>
|
125
125
|
<%= form.file_field :file %>
|
@@ -128,18 +128,11 @@ Alright, time to create our upload form. In order to do that, please open
|
|
128
128
|
|
129
129
|
<%= transloadit_jquerify :upload, :wait => true %>
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
def create
|
135
|
-
@upload = ActiveSupport::JSON.decode(params[:transloadit])
|
136
|
-
end
|
137
|
-
|
138
|
-
With this in place, we can modify the `create.html.erb` view to render the
|
139
|
-
uploaded and resized image:
|
131
|
+
With this in place, we can modify the `app/views/uploads/create.html.erb` view
|
132
|
+
to render the uploaded and resized image:
|
140
133
|
|
141
134
|
<h1>Resized upload image</h1>
|
142
|
-
<%= image_tag
|
135
|
+
<%= image_tag params['transloadit']['results']['resize'].first['url'] %>
|
143
136
|
|
144
137
|
That's it. If you've followed the steps closely, you should now be able to
|
145
138
|
try your first upload. Don't forget do start your rails server first:
|
data/lib/transloadit/rails.rb
CHANGED
@@ -5,11 +5,15 @@ require 'rails'
|
|
5
5
|
class Transloadit::Rails < Rails::Engine
|
6
6
|
CONFIG_PATH = 'config/transloadit.yml'
|
7
7
|
|
8
|
-
autoload :
|
8
|
+
autoload :ControllerExtensions, 'transloadit/rails/controller_extensions'
|
9
|
+
autoload :FormHelper, 'transloadit/rails/form_helper'
|
9
10
|
|
10
11
|
config.to_prepare do
|
11
12
|
# add the two helpers to the view stack
|
12
|
-
|
13
|
+
class ActionController::Base
|
14
|
+
include Transloadit::Rails::ControllerExtensions
|
15
|
+
helper TransloaditHelper
|
16
|
+
end
|
13
17
|
|
14
18
|
class ActionView::Helpers::FormBuilder
|
15
19
|
include Transloadit::Rails::FormHelper
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'transloadit/rails'
|
2
|
+
|
3
|
+
module Transloadit::Rails::ControllerExtensions
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_filter :decode_transloadit_json
|
8
|
+
end
|
9
|
+
|
10
|
+
def decode_transloadit_json
|
11
|
+
return unless params[:transloadit].present?
|
12
|
+
|
13
|
+
# wrap transloadit params in a HashWithIndifferentAccess
|
14
|
+
params[:transloadit] = ActiveSupport::HashWithIndifferentAccess.new(
|
15
|
+
ActiveSupport::JSON.decode params[:transloadit]
|
16
|
+
)
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Transloadit
|
2
|
+
class Rails
|
3
|
+
VERSION = '0.9.2'
|
4
|
+
end
|
5
5
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: transloadit-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Stephen
|
@@ -11,7 +11,8 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-04-
|
14
|
+
date: 2011-04-26 00:00:00 -04:00
|
15
|
+
default_executable:
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: transloadit
|
@@ -110,11 +111,13 @@ files:
|
|
110
111
|
- lib/transloadit-rails.rb
|
111
112
|
- lib/transloadit/generators.rb
|
112
113
|
- lib/transloadit/rails.rb
|
114
|
+
- lib/transloadit/rails/controller_extensions.rb
|
113
115
|
- lib/transloadit/rails/form_helper.rb
|
114
116
|
- lib/transloadit/rails/version.rb
|
115
117
|
- test/generators/transloadit/test_install_generator.rb
|
116
118
|
- test/test_helper.rb
|
117
119
|
- transloadit-rails.gemspec
|
120
|
+
has_rdoc: true
|
118
121
|
homepage: http://github.com/transloadit/rails-sdk/
|
119
122
|
licenses: []
|
120
123
|
|
@@ -138,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
141
|
requirements: []
|
139
142
|
|
140
143
|
rubyforge_project: transloadit-rails
|
141
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.6.2
|
142
145
|
signing_key:
|
143
146
|
specification_version: 3
|
144
147
|
summary: Official Rails gem for Transloadit
|