Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created April 1, 2012 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruprict/2276947 to your computer and use it in GitHub Desktop.
Save ruprict/2276947 to your computer and use it in GitHub Desktop.
Transloadit integration
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