Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails CarrierWave事务回滚_Ruby On Rails_Ruby_Google Cloud Platform_Carrierwave_Fog - Fatal编程技术网

Ruby on rails CarrierWave事务回滚

Ruby on rails CarrierWave事务回滚,ruby-on-rails,ruby,google-cloud-platform,carrierwave,fog,Ruby On Rails,Ruby,Google Cloud Platform,Carrierwave,Fog,我一直在尝试使用fog和谷歌云存储平台连接Carrierwave进行图像上传。然而,每当我的基本实现试图通过users\update访问数据库时,它就会被回滚。我尝试解决此问题失败,非常感谢您的帮助。Rails版本是5.0.1 **我已经退回到使用carrierwave的本地存储来尝试和调试这个问题,但我仍然有相同的回滚问题。我已经更新了文件以反映这一点 **更新:活动记录模型给出的错误消息是化身翻译丢失:en.errors.messages.mini\u magick\u processing

我一直在尝试使用fog和谷歌云存储平台连接Carrierwave进行图像上传。然而,每当我的基本实现试图通过
users\update
访问数据库时,它就会被回滚。我尝试解决此问题失败,非常感谢您的帮助。Rails版本是
5.0.1

**我已经退回到使用carrierwave的本地存储来尝试和调试这个问题,但我仍然有相同的回滚问题。我已经更新了文件以反映这一点

**更新:活动记录模型给出的错误消息是
化身翻译丢失:en.errors.messages.mini\u magick\u processing\u error

Gemfile

...
gem 'carrierwave', '~> 1.0'
gem 'mini_magick'
avatar\u uploader.rb:

class AvatarUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick

  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :display do
    process :resize_to_fill => [200, 200]
  end

  version :thumb do
    process :resize_to_fit => [80, 80]
  end

end
类AvatarUploader[200200] 结束 版本:thumb do 过程:调整_的大小以适应=>[80,80] 结束 结束 用户\u控制器.rb

class UsersController < ApplicationController
  before_action :authenticate_user!, only: [:edit, :update]
  before_action :check_authorization, only: [:edit, :update]
  before_action :set_user

  def show
  end

  def edit
  end

  def update
    if @user.update(user_params)
      redirect_to @user
    else
      flash.now[:notice] = "Something went wrong. Please try again."
      render :edit
    end
  end

  private
    def check_authorization
      unless current_user.id == params[:id].to_i
        redirect_to root_url
      end
    end

    def set_user
      @user = User.find(params[:id])
    end

    def user_params
      params.require(:user).permit(:avatar)
    end

end
class User < ApplicationRecord

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_and_belongs_to_many :meetings
  has_many :action_items
  has_many :tasks
  has_many :comments

  mount_uploader :avatar, AvatarUploader

end
<h1>Edit Profile</h1>

<%= form_for(@user, html: {multipart: true}) do |f| %>

  <%= f.file_field :avatar %>

  <%= f.submit "Save Change" %>

<% end %>
class UsersController
型号/用户.rb

class UsersController < ApplicationController
  before_action :authenticate_user!, only: [:edit, :update]
  before_action :check_authorization, only: [:edit, :update]
  before_action :set_user

  def show
  end

  def edit
  end

  def update
    if @user.update(user_params)
      redirect_to @user
    else
      flash.now[:notice] = "Something went wrong. Please try again."
      render :edit
    end
  end

  private
    def check_authorization
      unless current_user.id == params[:id].to_i
        redirect_to root_url
      end
    end

    def set_user
      @user = User.find(params[:id])
    end

    def user_params
      params.require(:user).permit(:avatar)
    end

end
class User < ApplicationRecord

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_and_belongs_to_many :meetings
  has_many :action_items
  has_many :tasks
  has_many :comments

  mount_uploader :avatar, AvatarUploader

end
<h1>Edit Profile</h1>

<%= form_for(@user, html: {multipart: true}) do |f| %>

  <%= f.file_field :avatar %>

  <%= f.submit "Save Change" %>

<% end %>
class用户
edit.html.erb

class UsersController < ApplicationController
  before_action :authenticate_user!, only: [:edit, :update]
  before_action :check_authorization, only: [:edit, :update]
  before_action :set_user

  def show
  end

  def edit
  end

  def update
    if @user.update(user_params)
      redirect_to @user
    else
      flash.now[:notice] = "Something went wrong. Please try again."
      render :edit
    end
  end

  private
    def check_authorization
      unless current_user.id == params[:id].to_i
        redirect_to root_url
      end
    end

    def set_user
      @user = User.find(params[:id])
    end

    def user_params
      params.require(:user).permit(:avatar)
    end

end
class User < ApplicationRecord

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  has_and_belongs_to_many :meetings
  has_many :action_items
  has_many :tasks
  has_many :comments

  mount_uploader :avatar, AvatarUploader

end
<h1>Edit Profile</h1>

<%= form_for(@user, html: {multipart: true}) do |f| %>

  <%= f.file_field :avatar %>

  <%= f.submit "Save Change" %>

<% end %>
编辑配置文件

请在您的头像阅读器中包含以下内容,然后重新启动服务器

def extension_white_list
  %w(jpg jpeg gif png)
end

我引用了以下内容

请在您的AvatarUploader中包含以下内容并重新启动服务器

def extension_white_list
  %w(jpg jpeg gif png)
end


我引用了以下内容,我的Imagemagick安装有问题。我重新安装并修复了问题

我的Imagemagick安装有问题。我重新安装并修复了问题

是否可以包括正在执行回滚查询的服务器日志?thanksI刚刚添加了服务器日志,尽管我不确定它会有多大帮助。谢谢你好,你能试着按照这篇文章的建议加入扩展白名单吗?谢谢Fabrizio,您是否可以包含正在执行回滚查询的服务器日志?thanksI刚刚添加了服务器日志,尽管我不确定它会有多大帮助。谢谢你好,你能试着按照这篇文章的建议加入扩展白名单吗?谢谢Fabrizio谢谢你的回复。我添加了
store\u dir
方法,并尝试使用
storage:file
来查看是否是雾导致了我的问题,但即使如此,我还是遇到了同样的回滚问题。@HarryZumwalt也许你没有注意到。但是我看到您没有包括'config.fog_provider='fog/google',这是基于Carrierwave github指南的必需内容。你可以在我的博文中看到。是的,我把这句话和附带的宝石一起加了上去,但没有成功。然而,正如我所说,我完全绕过了fog,尝试将carrierwave本地存储与
storage:file
一起使用,同时删除
storage:fog
。Carrierwave仍在回滚,这意味着错误与雾无关。ThanksI还更新了我的初始问题以反映我当前的问题。如果我将@user.errors.full_消息登录到我的控制台,它会给我
缺少的化身翻译:en.errors.messages.mini_magick_processing_error
。mini_magik会哽咽什么?谢谢你的回答。我添加了
store\u dir
方法,并尝试使用
storage:file
来查看是否是雾导致了我的问题,但即使如此,我还是遇到了同样的回滚问题。@HarryZumwalt也许你没有注意到。但是我看到您没有包括'config.fog_provider='fog/google',这是基于Carrierwave github指南的必需内容。你可以在我的博文中看到。是的,我把这句话和附带的宝石一起加了上去,但没有成功。然而,正如我所说,我完全绕过了fog,尝试将carrierwave本地存储与
storage:file
一起使用,同时删除
storage:fog
。Carrierwave仍在回滚,这意味着错误与雾无关。ThanksI还更新了我的初始问题以反映我当前的问题。如果我将@user.errors.full_消息登录到我的控制台,它会给我
缺少的化身翻译:en.errors.messages.mini_magick_processing_error
。mini_magik会被什么噎住?