用于图像上传的Rails主动存储的问题

时间:2019-08-15 19:12:17

标签: ruby-on-rails ruby

我试图根据此tutorial在我的Rails应用中设置图片上传。但是我遇到了:

ActiveSupport::MessageEncryptor::InvalidMessage

控制器:

    if !dont_save
      t = Track.new(params[:track])
      t.image.attach(params[:image])
      t.save
      redirect_to :action => "index", :controller => "playlists", :new_item => params[:track][:title].gsub(/[^a-z ]/, '').gsub(/\s+/, "")
    else
      redirect_to :action => "index", :controller => "playlists", :errors => uhohs
    end

表单模板:

<%= form_with scope: :track, url: playlists_index_path, local: true do |form| %>
  <p>
    <%= form.label "Date of memory" %><br>
    <%= form.date_field :memory_date %>
  </p>
  <p>
    <%= form.label "Image Related to Memory" %><br>
    <%= form.file_field :image, multiple: false, direct_upload: true %>
  </p>
<% end %>

跟踪模型:

class Track < ApplicationRecord
  belongs_to :timeline
  has_one_attached :image
end

0 个答案:

没有答案