Last active
December 16, 2015 01:09
-
-
Save px-amaac/5352570 to your computer and use it in GitHub Desktop.
The Code for my multiple picture uploads and the logs from the rails server
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 "/posts" for 127.0.0.1 at 2013-04-10 00:38:13 -0700 | |
Processing by PostsController#create as HTML | |
Parameters: {"utf8"=>"✓", "authenticity_token"=>"CJfQnNIl/e0UEwguNAjZ5bEP3snoO0CxXDjQOB3srQk=", "post"=>{"name"=>"New post", "description"=>"Not Working", "icon"=>#<ActionDispatch::Http::UploadedFile:0x0000000513c158 @original_filename="apple-logo.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[icon]\"; filename=\"apple-logo.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<Tempfile:/tmp/RackMultipart20130410-7778-1llvrgq>>, "post_pics_attributes"=>{"0"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x000000051438e0 @original_filename="officialLogo200.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"post[post_pics_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=\"post[post_pics_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 "posts" ("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", "Not Working"], ["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", "New Post"], ["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 post</h2> | |
<%= semantic_form_for @post, :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 :post_pics do |builder| %> | |
<% if builder.object.new_record? %> | |
<%= builder.input :image, :as => :file, :matching => "paperclip" %> | |
<% end %> | |
<% end %> | |
<%= f.action :submit, :as => :button %> | |
<% 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 Post < ActiveRecord::Base | |
attr_accessible :description, :name, :icon, :post_pics_attributes | |
has_many :post_pics, :dependent => :destroy | |
belongs_to :user | |
accepts_nested_attributes_for :post_pic, :reject_if => lambda{ |t| t['post_pic'].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: 'posts.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 PostPic < ActiveRecord::Base | |
belongs_to :post | |
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 PostsController < ApplicationController | |
before_filter :authenticate_user! | |
def index | |
@apps = Post.all | |
end | |
def show | |
@post = Post.find(params[:id]) | |
end | |
def new | |
@post = Post.new | |
4.times { @post.post_pics.build } | |
end | |
def create | |
@app = current_user.posts.build(params[:post]) | |
if @post.save | |
flash[:notice] = "Post Created" | |
redirect_to root_url | |
end | |
end | |
def update | |
@post = Post.find(params[:id]) | |
if @post.update_attributes(params[:post]) | |
redirect_to posts_path, :notice => "Post Updated." | |
else | |
redirect_to posts_path, :alert => "Unable to update Post." | |
end | |
end | |
def destroy | |
@post = current_user.posts.find_by_id(params[:id]) | |
redirect_to root_url if @post.nil? | |
else | |
@post.destroy | |
redirect_to posts_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment