Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To create an upload with paperclip, you need to use the name you provided for the <code>has_attached_file</code> line, on the model you defined it on. In your case, this will result in this view code:</p> <pre><code>&lt;%= form_for @accommodation, :html =&gt; { :multipart =&gt; true } do |f| %&gt; &lt;%= f.fields_for :photo do |photo_fields| %&gt; &lt;p&gt; Photo&lt;br /&gt; &lt;%= photo_fields.file_field :image %&gt; &lt;/p&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>In the controller:</p> <pre><code>class AccommodationsController &lt; ApplicationController # also protect create and update actions! before_filter :login_required, :only =&gt; [ :new, :create, :edit, :update ] def new # always make objects through their owner @accommodation = current_user.accommodations.build @accommodation.build_photo end def create @accommodation = current_user.accommodations.build(params[:accommodation]) if @accommodation.save # always redirect after successful save/update redirect_to @accommodation else render :new end end end </code></pre> <p>Tell Rails to handle the nested form:</p> <pre><code>class Accommodation has_one :photo accepts_nested_attributes :photo attr_accessible :photo_attributes, :title, :description, :etc end </code></pre> <p>And make sure to set the accessible attributes right in your photo model:</p> <pre><code>class Photo attr_accessible :image # individual attributes such as image_file_name shouldn't be accessible has_attached_file :image, :styles =&gt; "etc" end </code></pre> <p>Be sure to watch your log files to spot things that are protected by <code>attr_accessible</code>, but still are in your form.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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