The clip is not saved, no errors

I came across - went through documents, textbooks, etc., and I'm not sure what I'm doing wrong.

Another model in the project was created for Paperclip and functions during testing. It saves and retrieves the information of the attachment file in the database and places the file in a subfolder inside the public / system. I basically copied the corresponding code towards the model I'm working on

The model has the following line:

has_attached_file :document 

The table to which the model is attached has the necessary columns:

 document_file_name document_content_type document_file_size document_updated_at 

In the edit window, this (in haml):

 %h1 Knowledge Base: Edit Article = message_block :on => @article - form_for(@article, :url => knowledge_base_article_path(@article), :html => {:multipart => true}) do |f| #knowledgebase.clearfix %label Upload KB Document: %br = f.file_field :document - if @article.document.exists? %p = link_to "Current KB Attachment", @article.document.url %p = f.check_box :remove_document <br> = render :partial => "form", :locals => {:f => f} = submit_tag "Save changes" = link_to "Cancel", knowledge_base_article_path(@article) 

When I save a model instance, I can see in the log that Rails knows about the file I'm trying to load:

 Processing KnowledgeBase::ArticlesController#update (for 127.0.0.1 at 2010-11-18 19:21:01) [PUT] Parameters: {"article"=>{"document"=>#<File:/var/folders/EZ/EZKwznNSGq4PAI4ll9NUD++++TI/-Tmp-/RackMultipart20101118-58632-19nvbc8-0>, "question"=>"Craig Sandbox", "active"=>"0", "answer"=>"Nothing here, this is to test attachment functionality"}, "commit"=>"Save changes", "action"=>"update", "_method"=>"put", "authenticity_token"=>"MfH6RgLAQLnRBuf9WxgqWA+mIrDoBtYF+d4MW5DNCC0=", "id"=>"886", "controller"=>"knowledge_base/articles"} 

However, db values ​​are not updated at all for the four columns of document_ *, they remain NULL. The remaining columns in the same table are updated perfectly.

To make sure that the db columns are correctly named, I changed the db columns to something else and got an error when getting into the view, so I know that the db columns are correctly named.

To check the extraction of attachments, I manually created the subfolders inside the public / system (where the attachment would be enabled when the model instance was saved), and manually changed the four document_ * columns in the table. Then I turned to the same look, and this showed the correct attachment.

I noticed that I also cannot remove the attachment when "remove_document" is set. The db values ​​for document_ * remain unchanged.

As if the read operation in these four columns works, but the write operation does not work (although I can have Rails, change other columns in the same table if I change something in the model instance on the edit page),

Any ideas what I can do wrong here? I'm sure I missed something obvious.

+4
source share
1 answer

How do you update the Article model in the controller? Are you using @article.update_attributes(params[:article]) ?

The reason, if you are then, may be caused by the misuse of attr_protected or attr_accessible . In this case, you can try to assign a file

 @article.document = params[:article][:document] 
+8
source

All Articles