Paperclip is making me crazy

seems pretty simple, my model…

has_attached_file :pic_1, :styles => { :thumb => “120x90” },
:url => “/:attachment/:id_:style.:extension”,
:path => “:rails_root/public/system/:attachment/:id_:style.:extension”

my view…

<% form_tag(:action => ‘create’, :html => { :multipart => true }) do -%>
Image
<%= file_field ‘ad’, ‘pic_1’ %>
<%= submit_tag ’ Save ', :class => ‘button’ %>

and I save and the development.log shows expected…
Processing Admin::AdsController#create (for 127.0.0.1 at 2010-02-13
17:49:15) [POST]
Parameters: {“html”=>{“multipart”=>“true”}, “commit”=>" Save “,
“ad”=>{“salesprogram_id”=>“3”, “pic_1”=>“DSC01760.JPG”,
“active”=>“true”}, “action”=>“create”, “authenticity_token”=>”-",
“controller”=>“admin/ads”}

But the SQL Insert for pic_1_file_name, pic_1_file_size,
pic_1_content_type and pic_1_updated_at are all NULL

and I’ve googled and flailed and googled and flailed but I cannot make
this work.

Can anyone toss me a bone here?

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

Craig W. wrote:

seems pretty simple, my model…

has_attached_file :pic_1, :styles => { :thumb => “120x90” },
:url => “/:attachment/:id_:style.:extension”,
:path => “:rails_root/public/system/:attachment/:id_:style.:extension”

my view…

<% form_tag(:action => ‘create’, :html => { :multipart => true }) do -%>
Image
<%= file_field ‘ad’, ‘pic_1’ %>
<%= submit_tag ’ Save ', :class => ‘button’ %>

and I save and the development.log shows expected…
Processing Admin::AdsController#create (for 127.0.0.1 at 2010-02-13
17:49:15) [POST]
Parameters: {“html”=>{“multipart”=>“true”}, “commit”=>" Save “,
“ad”=>{“salesprogram_id”=>“3”, “pic_1”=>“DSC01760.JPG”,
“active”=>“true”}, “action”=>“create”, “authenticity_token”=>”-",
“controller”=>“admin/ads”}

But the SQL Insert for pic_1_file_name, pic_1_file_size,
pic_1_content_type and pic_1_updated_at are all NULL

and I’ve googled and flailed and googled and flailed but I cannot make
this work.

Can anyone toss me a bone here?

Craig

Parameters: {“html”=>{“multipart”=>“true”}, “commit”=>" Save ",

“ad”=>{“salesprogram_id”=>“3”, “pic_1”=>“DSC01760.JPG”,
“active”=>“true”}, “action”=>“create”, “authenticity_token”=>"-",
“controller”=>“admin/ads”} actually is not what you want to see in the params hash; the value at “pic_1” should be a File object…

:html isn’t an option form_tag understands; use use :multipart => true
for your options hash.
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001729

On Sun, 2010-02-14 at 02:53 +0100, Paul H. wrote:

Image

Parameters: {“html”=>{“multipart”=>“true”}, “commit”=>" Save ",

“ad”=>{“salesprogram_id”=>“3”, “pic_1”=>“DSC01760.JPG”,
“active”=>“true”}, “action”=>“create”, “authenticity_token”=>"-",
“controller”=>“admin/ads”} actually is not what you want to see in the params hash; the value at “pic_1” should be a File object…

:html isn’t an option form_tag understands; use use :multipart => true
for your options hash.
http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M001729


that’s what I get for trying to follow the examples supplied by the
project…I actually caught it before I read your e-mail and indeed, you
were right on the mark. The last time I did picture uploads, etc. was
with Rails 1.2 & rmagick and everyone says how much better paperclip is
which appears to be the case but I kept looking at the model code
without ever suspecting that their sample code had the multipart => true
that simply didn’t work.

Thanks

Craig


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs