cloudinary:“ uploaded_file = params [:person] [:picture] .path”在本地运行,但在heroku部署上不运行

时间:2019-06-06 05:49:31

标签: ruby-on-rails cloudinary

通过cloudinary上载图像可在localhost上进行,但在rails app部署在heroku上时则无法。 (即“很抱歉,但是出了点问题”)

代码:upload_file = params [:log] [:picture] .path cloudinary_file = Cloudinary :: Uploader.upload(uploaded_file,:folder =>“铁路新闻”)。

我已经指出,在本地打印出uploaded_file会显示“ / var / folders / 2f / ...”,但是在heroku中会显示“ /tmp/RackMultipart20190606-4-1i7nfxh.jpg”。

在logs_controller.rb文件中:

def update
    @log = Log.find(params[:id])

    if params[:log][:picture]
      p "begin cloudinary upload if there is image: "
      uploaded_file = params[:log][:picture].path
      p "printing uploaded_file path below: "
      p uploaded_file
      cloudinary_file = Cloudinary::Uploader.upload(uploaded_file, :folder => "journal-on-rails")

      p "printing cloudinary_file below: "
      p cloudinary_file

      p "printing cloudinary_file url below: "
      p cloudinary_file["url"]


      @log.attributes = {:image => cloudinary_file["public_id"]}
    else
      log_params[:image] = @log.image
    end

    respond_to do |format|
      if @log.update(log_params)
        format.html { redirect_to @log, notice: "Entry updated!" }
        p "Log updated!"
      else
        format.html { render action: 'logs/edit' }
      end
    end
  end

在edit.html.erb文件中:

<<%= form_with scope: :log, model: @log, local: true do |form| %>
  <p>
    <%= form.label :title, 'Entry Title' %><br>
    <%= form.text_field :title, class: "title-text-field" %><br>
        <%= form.label :content, "Content - Great! Felt better?" %><br>
        <%= form.text_area :content, class: "log-text-area"%><br>
        <%= form.label :picture %><br>
        <%= cl_image_tag(@log.image, :width => 350, :fetch_format=>:auto, :crop=>"scale") %><br>
    <%= form.file_field :picture %><br>
  </p>
  <p>
    <%= form.submit %>
  </p>
<% end %>

<%= link_to 'Back', log_path, class: 'btn btn-primary' %>

我的heroku Journal on Rails网络应用程序:https://agenda-journal-on-rails.herokuapp.com/

在localhost中,我可以创建标题,正文,还可以通过Cloudinary上传图像。根路径显示日记条目/日志的列表,以及上载图像的缩略图。但是在heroku中,当在生产环境中部署时,所有的cloudinary函数都无法正常工作。结果,没有缩略图。

我得出的结论是,Cloudinary的cl_image_tag()帮助器方法正在运行。因为我可以获取它以获取我的cloudinary帐户中的另一个public_id。但是在Heroku中,当执行POST方法进行编辑时。我在“ heroku日志--tail”中收到此错误:

2019-06-06T05:18:07.303488 + 00:00 heroku [router]:at = info method = POST path =“ / logs / 3” host = agenda-journal-on-rails.herokuapp.com request_id = f7c5bdff-79e2-4f28-b500-f5ffecdc4246 fwd =“ 129.126.207.229” dyno = web.1 connect = 0ms service = 819ms status = 500 bytes = 1827 protocol = https

0 个答案:

没有答案