Created
April 10, 2013 08:26
-
-
Save px-amaac/5352817 to your computer and use it in GitHub Desktop.
Appdomumsite Having trouble with image uploads. The icon shows up but the multiple nested files are not showing up.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App < ActiveRecord::Base | |
attr_accessible :description, :name, :icon, :app_screenshots_attributes | |
has_many :app_screenshots, :dependent => :destroy | |
belongs_to :user | |
accepts_nested_attributes_for :app_screenshots, :reject_if => lambda{ |t| t['app_screenshot'].nil? }, :allow_destroy => true | |
validates :name, presence: true | |
validates :description, presence: true | |
has_attached_file :icon, :styles =>{ :medium => "300x300>", :thumb => "150x150>" }, :default_url => "/images/:style/missing.png" | |
default_scope order: 'apps.created_at DESC' | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppScreenshot < ActiveRecord::Base | |
belongs_to :app | |
has_attached_file :image, :styles => { :small => "480x320>", :large => "920x640>"} | |
validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png'] | |
attr_accessible :caption, :image | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppsController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
@apps = App.all | |
end | |
def show | |
@app = App.find(params[:id]) | |
end | |
def new | |
@app = App.new | |
4.times { @app.app_screenshots.build } | |
end | |
def create | |
@app = current_user.apps.build(params[:app]) | |
if @app.save | |
flash[:notice] = "App Created" | |
redirect_to root_url | |
end | |
end | |
def update | |
@app = App.find(params[:id]) | |
if @app.update_attributes(params[:app]) | |
redirect_to apps_path, :notice => "App Updated." | |
else | |
redirect_to apps_path, :alert => "Unable to update App." | |
end | |
end | |
def destroy | |
@app = current_user.apps.find_by_id(params[:id]) | |
redirect_to root_url if @app.nil? | |
else | |
@app.destroy | |
redirect_to apps_path | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started POST "/apps" for 127.0.0.1 at 2013-04-10 00:38:13 -0700 | |
Processing by AppsController#create as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CJfQnNIl/e0UEwguNAjZ5bEP3snoO0CxXDjQOB3srQk=", "app"=>{"name"=>"dsafasdf", "description"=>"asdfasdf", "icon"=>#<ActionDispatch::Http::UploadedFile:0x0000000513c158 @original_filename="apple-logo.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"app[icon]\"; filename=\"apple-logo.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130410-7778-1llvrgq>>, "app_screenshots_attributes"=>{"0"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x000000051438e0 @original_filename="officialLogo200.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"app[app_screenshots_attributes][0][image]\"; filename=\"officialLogo200.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130410-7778-1jymz7d>>}, "1"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x00000005142cd8 @original_filename="officialLogo-100x197.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"app[app_screenshots_attributes][1][image]\"; filename=\"officialLogo-100x197.png\"\r\nContent-Type: image/png\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130410-7778-122h461>>}}}, "button"=>""} | |
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 | |
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: convert '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' -auto-orient -resize "300x300>" '/tmp/apple-logo20130410-7778-1eiuwqe20130410-7778-1dvaulo' | |
Command :: file -b --mime '/tmp/apple-logo20130410-7778-1eiuwqe20130410-7778-1dvaulo' | |
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: identify -format %m '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' | |
Command :: convert '/tmp/apple-logo20130410-7778-1eiuwqe.jpg[0]' -auto-orient -resize "150x150>" '/tmp/apple-logo20130410-7778-1eiuwqe20130410-7778-1q09w5i' | |
Command :: file -b --mime '/tmp/apple-logo20130410-7778-1eiuwqe20130410-7778-1q09w5i' | |
(0.1ms) begin transaction | |
Binary data inserted for `string` type on column `icon_content_type` | |
SQL (0.9ms) INSERT INTO "apps" ("created_at", "description", "icon_content_type", "icon_file_name", "icon_file_size", "icon_updated_at", "name", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [["created_at", Wed, 10 Apr 2013 07:38:14 UTC +00:00], ["description", "asdfasdf"], ["icon_content_type", "image/jpeg"], ["icon_file_name", "apple-logo.jpg"], ["icon_file_size", 57753], ["icon_updated_at", Wed, 10 Apr 2013 07:38:13 UTC +00:00], ["name", "dsafasdf"], ["updated_at", Wed, 10 Apr 2013 07:38:14 UTC +00:00], ["user_id", 1]] | |
[paperclip] Saving attachments. | |
(151.7ms) commit transaction | |
Redirected to http://localhost:3000/ | |
Completed 302 Found in 605ms (ActiveRecord: 153.2ms) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Create New App</h2> | |
<%= semantic_form_for @app, :html => { :multipart => true } do |f| %> | |
<%= f.input :name, :as => :string %> | |
<%= f.input :description, :as => :text %> | |
<%= f.input :icon, :as => :file, :matching => "paperclip" %> | |
<%= f.semantic_fields_for :app_screenshots do |builder| %> | |
<% if builder.object.new_record? %> | |
<%= builder.input :image, :as => :file, :matching => "paperclip" %> | |
<% end %> | |
<% end %> | |
<%= f.action :submit, :as => :button %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment