Created
April 1, 2012 16:45
-
-
Save ruprict/2276947 to your computer and use it in GitHub Desktop.
Transloadit integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PicturesController < ApplicationController | |
before_filter :extract_tl_parameters, only: :create | |
def index | |
@picture = Picture.new | |
@pictures = Picture.all | |
end | |
def show | |
@picture = Picture.find(params[:id]) | |
end | |
def create | |
@picture = Picture.create!(params[:picture]) | |
redirect_to @picture | |
end | |
private | |
def extract_tl_parameters | |
tl_params= ActiveSupport::JSON.decode(params["transloadit"] ) | |
params[:picture][:assembly_id] = tl_params["assembly_id"] | |
params[:picture][:name] = generate_file_name(tl_params) | |
end | |
def generate_file_name(tl_params) | |
"#{tl_params["uploads"][0]["basename"]}.#{tl_params["uploads"][0][ "ext" ].downcase}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment