Avatar not loading with paperclip and aws-sdk gem

I have a problem loading my avatar. He worked once for me, but this time I have to be blind. I use paperclip and aws-sdk gem and configure everything as described here.

I tested it with two buckets. One with standard us-location and one with eu-west-1 . Nothing works.

Here is my code:

config / s 3.yml

 development: bucket: *** access_key_id: *** secret_access_key: *** test: bucket: *** access_key_id: *** secret_access_key: *** production: bucket: *** access_key_id: *** secret_access_key: *** 

application / model / art.rb

 class Art < ActiveRecord::Base attr_accessible :created_at, :description, :name, :avatar has_attached_file :avatar, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :url => ':set_alias_url', :path => "/:style/:id/:filename.:extension", :bucket => '***' end 

application / controller / arts_controller.rb

 class ArtsController < ApplicationController ... def create @art = Art.new(params[:art]) if @art.save flash[:notice] = "sucessfully saved upload" redirect_to arts_path else flash[:notice] = "error" render "new" end ... 

application / views / art / new.html.erb

 <h1>Arts#new</h1> <p>Find me in app/views/arts/new.html.erb</p> <%= form_for(@art, :url => arts_path, :html => { :multipart => true }) do |f| %> <%= f.label :name %> <br/> <%= f.text_field :name %> <br/> <%= f.label :description %> <br/> <%= f.text_field :description %> <br/> <%= f.label :avatar %> <br/> <%= f.file_field :avatar %> <br/> <%= f.submit %> <% end %> 

I searched the website for 2 days, but I can not find my mistake. Here is the response from the server:

 POST "/arts/new" for 127.0.0.1 at 2012-12-19 12:11:39 +0100 Processing by ArtsController#new as HTML Parameters: {"utf8"=>"βœ“", "authenticity_token"=>"ZyZFfSaTl9CQpL5kOXyt/rcoi+SCuNp5/deCYda83sE=", "art"=>{"name"=>"asdf", "description"=>"asdf", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x0000000296e0b8 @original_filename="lakritz10.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"art[avatar]\"; filename=\"lakritz10.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121219-5804-1rnvkmj>>}, "commit"=>"Create Art 

So can someone help me fix this?

early.

EDIT: It seems that even without attachment, nothing is stored in the database. It is connected ...

EDIT_SOLUTION: to solve my specific problem I had to change routes.rb I previously assumed that the entry

 match "arts/new", :to => "arts#new", :as => 'arts' 

will do the job. This was not the case. I had to change the line to:

 resources :arts 

Because I don’t understand how the routes work exactly, I can’t explain it.

+4
source share
1 answer

Your line:

 match "arts/new", :to => "arts#new", :as => 'arts' 

creates a route to the new action. It maps arts_path to arts/new , which is then the object of your form. You really need to submit the arts#create form, which makes the resource automatically for POST with a new object.

0
source

All Articles