Skip to content

Instantly share code, notes, and snippets.

@RSpace
Created March 26, 2009 11:28
Show Gist options
  • Save RSpace/86020 to your computer and use it in GitHub Desktop.
Save RSpace/86020 to your computer and use it in GitHub Desktop.
require 'mime/types'
class AssetsController < ApplicationController
session :cookie_only => false, :only => :create
def create
@asset = Asset.new(params[:asset])
respond_to do |wants|
wants.html do
if @asset.save
redirect_to asset_url(@asset)
else
render :action => :new
end
end
wants.json do
@asset.content_type = MIME::Types.type_for(@asset.filename).to_s
if @asset.save
render :json => { :result => 'success', :asset => @asset.id }
else
render :json => { :result => 'error', :error => @asset.errors.full_messages.to_sentence }
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment