Skip to content

Instantly share code, notes, and snippets.

@danhere
Created February 2, 2011 22:04
Show Gist options
  • Save danhere/808551 to your computer and use it in GitHub Desktop.
Save danhere/808551 to your computer and use it in GitHub Desktop.
Results_Controller
Started POST "/results" for xxx.xxx.xxx.xxx at 2011-02-02 16:57:44 -0500
Processing by ResultsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x1Fxj2OGNfbGs6fDskHa7jB3LhJswDkEUG4BYOx2iBw=", "result"=>{"title"=>"Testing", "short_url"=>"test", "result_file"=>#<ActionDispatch::Http::UploadedFile:0xba42ae4 @original_filename="ljrind11.htm", @content_type="text/html", @headers="Content-Disposition: form-data; name=\"result[result_file]\"; filename=\"ljrind11.htm\"\r\nContent-Type: text/html\r\n", @tempfile=#<File:/tmp/RackMultipart20110202-29224-1qc2x8y>>, "created_at(1i)"=>"2011", "created_at(2i)"=>"2", "created_at(3i)"=>"2"}, "commit"=>"Upload"}
Completed in 232ms
Errno::EACCES (Permission denied - /var/apps/nests/public/tmp/results):
app/controllers/results_controller.rb:18:in `create'
class ResultsController < ApplicationController
before_filter :authenticate_admin!, :except => [:index, :show]
respond_to :html, :xml
def index
@results = Result.find(:all, :order => 'created_at DESC').paginate(:page => params[:page])
end
def show
@result = Result.find_by_short_url(params[:id]) || Result.find_by_id(params[:id])
respond_with(@result, :location => result_path)
end
def new
@result = Result.new
end
def create
@result = Result.create(params[:result])
if @result.save
flash[:success] = 'Result uploaded successfully!'
respond_with(@result, :location => @result)
else
flash[:error] = 'Upload failed.'
respond_with(@result, :location => new_result_path)
end
end
def edit
@result = Result.find(params[:id])
end
def update
@result = Result.find(params[:id])
if @result.update_attributes(params[:result])
flash[:success] = 'Result was successfully updated.'
respond_with(@result, :location => results_path)
else
flash[:error] = 'Oh snap. The hampsters stopped running. Try again.'
respond_with(@result, :location => edit_result_path)
end
end
def destroy
@result = Result.find_by_short_url(params[:id])
@result.destroy
flash[:success] = "The result was terminated. Pew pew pew."
respond_with(nil, :location => results_path)
end
end
class Result < ActiveRecord::Base
cattr_reader :per_page
@@per_page = 30
def to_param
short_url
end
mount_uploader :result_file, ResultFileUploader
validates :title, :presence => true,
:length => {:minimum => 5}
validates :short_url, :presence => true,
:uniqueness => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment