public
Created

  • Download Gist
development.log
1 2 3 4 5 6 7 8 9 10
Started POST "/landscapes" for 127.0.0.1 at 2011-07-22 11:07:18 -0500
Processing by LandscapesController#create as JSON
Parameters: {"landscape"=>{"id"=>0, "name"=>"Newscape", "city"=>"Fun city", "state"=>"LA", "zip"=>"71457", "images_attributes"=>[{"id"=>0, "image_data"=>"Im a bunch of image data image data image data", "is_thumbnail"=>1}], "address1"=>"Cool place"}}
SQL (61.9ms) SHOW TABLES[
Image Load (0.3ms) SELECT `images`.* FROM `images` WHERE `images`.`id` IN (0) AND (`images`.imageable_id = 0 AND `images`.imageable_type = 'Landscape')
Completed in 242ms
 
ActiveRecord::RecordNotFound (Couldn't find Image with ID=0 for Landscape with ID=0):
app/controllers/landscapes_controller.rb:44:in `new'
app/controllers/landscapes_controller.rb:44:in `create'
images_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
class ImagesController < ApplicationController
# GET /images
# GET /images.json
def index
@imageable = find_imageable
@images = @imageable.images
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @images }
end
end
 
# GET /images/1
# GET /images/1.json
def show
@image = Image.find(params[:id])
@imageable = find_imageable
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @image }
end
end
 
# GET /images/new
# GET /images/new.json
def new
@image = Image.new
@imageable = find_imageable
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @image }
end
end
 
# GET /images/1/edit
def edit
@image = Image.find(params[:id])
@imageable = find_imageable
end
 
# POST /images
# POST /images.json
def create
@imageable = find_imageable
@image = @imageable.images.build(params[:image])
respond_to do |format|
if @image.save
format.html { redirect_to([@imageable, @image], :notice => 'Image was successfully created.') }
format.json { render :json => @image, :status => :created, :location => @image }
else
format.html { render :action => "new" }
format.json { render :json => @image.errors, :status => :unprocessable_entity }
end
end
end
 
# PUT /images/1
# PUT /images/1.json
def update
@image = Image.find(params[:id])
@imageable = find_imageable
respond_to do |format|
if @image.update_attributes(params[:image])
format.html { redirect_to([@imageable, @image], :notice => 'Image was successfully updated.') }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @image.errors, :status => :unprocessable_entity }
end
end
end
 
# DELETE /images/1
# DELETE /images/1.json
def destroy
@image = Image.find(params[:id])
@image.destroy
@imageable = find_imageable
respond_to do |format|
format.html { redirect_to(polymorphic_path([@imageable, :images])) }
format.json { head :ok }
end
end
private
 
def find_imageable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
end
landscapes_controller.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
class LandscapesController < ApplicationController
# GET /landscapes
# GET /landscapes.json
def index
@landscapes = Landscape.all
 
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @landscapes }
end
end
 
# GET /landscapes/1
# GET /landscapes/1.json
def show
@landscape = Landscape.find(params[:id])
 
respond_to do |format|
format.html # show.html.erb
format.json { render :json => @landscape.to_json(:include => :images) }
end
end
 
# GET /landscapes/new
# GET /landscapes/new.json
def new
@landscape = Landscape.new
 
respond_to do |format|
format.html # new.html.erb
format.json { render :json => @landscape }
end
end
 
# GET /landscapes/1/edit
def edit
@landscape = Landscape.find(params[:id])
@landscape.images.build
end
 
# POST /landscapes
# POST /landscapes.json
def create
@landscape = Landscape.new(params[:landscape])
respond_to do |format|
if @landscape.save
format.html { redirect_to(@landscape, :notice => 'Landscape was successfully created.') }
format.json { render :json => @landscape, :status => :created, :location => @landscape }
else
format.html { render :action => "new" }
format.json { render :json => @landscape.errors, :status => :unprocessable_entity }
end
end
end
 
# PUT /landscapes/1
# PUT /landscapes/1.json
def update
@landscape = Landscape.find(params[:id])
 
respond_to do |format|
if @landscape.update_attributes(params[:landscape])
format.html { redirect_to(@landscape, :notice => 'Landscape was successfully updated.') }
format.json { head :ok }
else
format.html { render :action => "edit" }
format.json { render :json => @landscape.errors, :status => :unprocessable_entity }
end
end
end
 
# DELETE /landscapes/1
# DELETE /landscapes/1.json
def destroy
@landscape = Landscape.find(params[:id])
@landscape.destroy
 
respond_to do |format|
format.html { redirect_to(landscapes_url) }
format.json { head :ok }
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.