I have a Rails 5.2 app in which I am using activerecord attachments to upload photos as attachments.
They upload fine, but come out rotated. I have seen other Stack Overflow questions that deal with Paperclip uploads and this issue (like this one or this one), but since Paperclip is depreciated with Rails 5.2 the initializer they say to fix is not present.
Can anyone figure out what's going wrong here?
My form is like this:
<%= simple_form_for [@capsule, CapsuleItem.new] do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="form-inputs">
<div class="form-group">
<%= f.label :item_date %>
<input placeholder="Date of Photograph" type="text" id="date" class="form-control datepicker"></input>
<%= f.hidden_field :item_date, id: "dateHolder", class: "hiddenDateField" %>
</div> <!-- form group -->
<%= f.input :photo %>
<%= f.input :title %>
<%= f.input :caption %>
<%= f.hidden_field :capsule %>
</div>
<div class="form-actions text-center">
<%= f.button :submit, value: "Add Photo to Time Capsule", class: "btn btn-danger" %>
</div>
<% end %>
My controller capsule_item#create
method is here:
def create
@capsule = Capsule.find(params[:capsule_id])
@capsule_item = @capsule.capsule_items.build(capsule_item_params)
@capsule_item.user = current_user
respond_to do |format|
if @capsule_item.save
format.html { redirect_to @capsule, notice: 'Capsule item was successfully created.' }
format.json { render :show, status: :created, location: @capsule_item }
else
format.html { render :new }
format.json { render json: @capsule_capsule_item.errors, status: :unprocessable_entity }
end
end
end
And my CapsuleItem
model is like this:
class CapsuleItem < ApplicationRecord
belongs_to :user
belongs_to :capsule
has_one_attached :photo
end
The image is being displayed like this:
<%= image_tag rails_blob_url(item.photo.variant(auto_orient: true)), class: "card-img-top" %>