Note that there are some explanatory texts on larger screens.

plurals
  1. PORails with Paperclip ignore empty attachments
    primarykey
    data
    text
    <p>I am using paperclip with rails and it works fine, however my problem is when updating if the i don't reselect the image, then it saves the record as nil. Here is my code:</p> <pre><code>&lt;div class="form-group"&gt; &lt;div class="media"&gt; &lt;%= image_tag program_avatar(b), :id =&gt; 'avatar', :class =&gt; 'thumbnail media-object pull-left', :height =&gt; 100, :width =&gt; 100 %&gt; &lt;div class="media-body padding-top-40"&gt; &lt;%= b.file_field :avatar, :class =&gt; 'file-upload' %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;div class="media"&gt; &lt;%= image_tag program_banner(b), :class =&gt; 'thumbnail media-object pull-left', :height =&gt; 100, :width =&gt; 300 %&gt; &lt;div class="media-body padding-top-40"&gt; &lt;%= b.file_field :banner, :class =&gt; 'file-upload' %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and the controller:</p> <pre><code>respond_to do |format| if @program.update(program_params) format.html { redirect_to(program_path(@program), :notice =&gt; "Program updated") } format.js { render :json =&gt; @program.json } else format.html { render :new, :notice =&gt; "Error please try again" } format.js { render :json =&gt; "Error please try again" } end end </code></pre> <p>The models:</p> <p><em>Book model</em>:</p> <pre><code>has_one :book_content, :dependent =&gt; :destroy accepts_nested_attributes_for :book_content, :allow_destroy =&gt; true </code></pre> <p>Book_content model:</p> <pre><code>has_attached_file :avatar, :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;" }, :default_url =&gt; "/images/:style/missing.png" has_attached_file :banner, :styles =&gt; { :header =&gt; "600x150", :setting =&gt; "300x100" }, :default_url =&gt; "/images/:style/found.jpeg" belongs_to :book </code></pre> <p>this is a nested form, but because it has multiple attachments so i cannot use <code>reject_if</code></p> <p>How can tell paperclip to keep the original files if no file is selected?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload