Ruby on rails Carrierwave和Jcrop以及Desive,Jcrop不是裁剪

Ruby on rails Carrierwave和Jcrop以及Desive,Jcrop不是裁剪,ruby-on-rails,ruby-on-rails-4,devise,carrierwave,jcrop,Ruby On Rails,Ruby On Rails 4,Devise,Carrierwave,Jcrop,Carrierwave和Jcrop以及Desive,Jcrop不是裁剪 我使用Desive进行身份验证,并使用Carrierwave+Jcrop(gem'Jcrop-rails-v2')为用户裁剪他们的化身。我遵循这一点,在完成铁路运输计划后,出于某种原因,它没有被裁剪。我不确定它是否与design或Jcrop 请看下面我的代码和截图。正如您在屏幕截图中看到的,单击“裁剪”后,图像应与“预览”相同,但它只会变为实际图像的较小版本。 crop.html.erb 注册(u controller.e

Carrierwave和Jcrop以及Desive,Jcrop不是裁剪

我使用Desive进行身份验证,并使用Carrierwave+Jcrop(gem'Jcrop-rails-v2')为用户裁剪他们的化身。我遵循这一点,在完成铁路运输计划后,出于某种原因,它没有被裁剪。我不确定它是否与
design
Jcrop

请看下面我的代码和截图。正如您在屏幕截图中看到的,单击“裁剪”后,图像应与“预览”相同,但它只会变为实际图像的较小版本。

crop.html.erb 注册(u controller.erb)
类注册控制器true
如果参数[:用户][:图像]。是否存在?
渲染“裁剪”
其他的
将_重定向到“/users/3”
结束
其他的
渲染“编辑”
结束
结束
受保护的
结束
image_uploader.rb
class ImageUploader
def配置\帐户\更新\参数

设计参数消毒器。对于(:account\u update)您是否也可以连接上传程序?也不确定您是否知道哪些参数在
[account\u update]
()上消毒。我很惊讶您的图像为什么会保存下来,请检查更新的问题。这是我的[account_update]
设计参数清洁剂。对于(:account_update){u.permit(:username,:image)}
ok酷,但是你在哪里允许
crop_x
crop_y
crop_w
也在我的用户模型(user.rb)中附上你的参数,我写了
attr_访问者:crop_x,
,这有点奇怪,因为我使用的是Rails 4。这是对的,但因为你是批量分配的,因为我看不到你在任何地方显式分配crox|[x | y | h | w]
你也必须清理那些参数,因此我要求你在问题中附加
参数
<h1>Crop Avatar</h1>

<%= image_tag @user.image_url(:large), id: "cropbox" %>

<h4>Preview</h4>
<div style="width:100px; height:100px; overflow:hidden">
  <%= image_tag @user.image.url(:large), :id => "preview" %>
</div>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
  <% %w[x y w h].each do |attribute| %>
    <%= f.hidden_field "crop_#{attribute}" %>
  <% end %>
  <div>
    <%= f.submit "Crop" %>
  </div>
<% end %>
jQuery ->
  new ImageCropper()

class ImageCropper
  constructor: ->
    $('#cropbox').Jcrop
      aspectRatio: 1
      setSelect: [0, 0, 600, 600]
      onSelect: @update
      onChange: @update

  update: (coords) =>
    $('#user_crop_x').val(coords.x)
    $('#user_crop_y').val(coords.y)
    $('#user_crop_w').val(coords.w)
    $('#user_crop_h').val(coords.h)
    @updatePreview(coords)

  updatePreview: (coords) =>
          $('#preview').css
                  width: Math.round(100/coords.w * $('#cropbox').width()) + 'px'
                  height: Math.round(100/coords.h * $('#cropbox').height()) + 'px'
                  marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px'
                  marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px'
class RegistrationsController < Devise::RegistrationsController

    def update
    account_update_params = devise_parameter_sanitizer.sanitize(:account_update)
    @user = User.find(current_user.id)

        successfully_updated = if account_update_params[:password].blank?
           params[:user].delete(:current_password)
           @user.update_without_password(devise_parameter_sanitizer.sanitize(:account_update))
         else
           @user.update_with_password(devise_parameter_sanitizer.sanitize(:account_update))
         end

         if successfully_updated
            set_flash_message :notice, :updated
            sign_in @user, :bypass => true
            if params[:user][:image].present?
              render "crop"
            else
              redirect_to "/users/3"
            end
         else
            render "edit"
         end
  end


protected



end
class ImageUploader < CarrierWave::Uploader::Base

  include CarrierWave::RMagick

  storage :file

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

version :large do
    resize_to_limit(600, 600)
  end

  version :thumb do
    process :crop
    resize_to_fill(100, 100)
  end

  def crop
    if model.crop_x.present?
      resize_to_limit(600, 600)
      manipulate! do |img|
        x = model.crop_x.to_i
        y = model.crop_y.to_i
        w = model.crop_w.to_i
        h = model.crop_h.to_i
        img.crop!(x, y, w, h)
      end
    end
  end


end
def configure_account_update_params
    devise_parameter_sanitizer.for(:account_update) << [:crop_x, :crop_y, :crop_w..