Skip to content

Instantly share code, notes, and snippets.

@milushov
Created December 21, 2012 08:38
Show Gist options
  • Save milushov/4351487 to your computer and use it in GitHub Desktop.
Save milushov/4351487 to your computer and use it in GitHub Desktop.
class Dashboard::AttachmentsController < ApplicationController
before_filter :prepare
FORMS = [Question]# Ask Application Feedback Occupation]
def create
@attachment = Attachment.new params[:attachment]
unless @access_error
@attachment.attachable_id = @temp_attachable_id
@attachment.attachable_type = attachable_type || ''
if @attachment.save
session[:temp_attachments][:attachments_ids] << @attachment.id
end
end
end
def destroy
end
private
def prepare
@temp_attachable_id = params[:attachment].delete(:temp_attachable_id).to_i
real_temp_attachable_id = session[:temp_attachments][:attachable_id].to_i
@access_error = @temp_attachable_id != real_temp_attachable_id ? true : false
end
def attachable_type
type = FORMS.detect { |c| params["#{c.name.underscore}_id"] } || ''
type.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment