4

我正在尝试使用 Rails Admin 设置自定义裁剪操作。

我已设置操作,但在传递裁剪坐标以保存裁剪图像时遇到问题。我想在表单中传递“crop_x”等属性,但由于某种原因,它们没有被传递。也许我的表格设置错误?

这是我的表单代码:

    = form_for @object, method: :put, :url => crop_path(:model_name => @abstract_model.to_param, :id => @object.id) do |f|
      - %w[x y w h].each do |attribute|
        = f.text_field "crop_#{attribute}", id: "crop_#{attribute}"

      .form-actions
        = f.submit 'Crop Image', class: 'btn btn-primary'

这是我的 Rails 管理员自定义裁剪操作:

    require 'rails_admin/config/actions'
    require 'rails_admin/config/actions/base'

    module RailsAdminCrop
    end

    module RailsAdmin
      module Config
        module Actions
          class Crop < RailsAdmin::Config::Actions::Base
            RailsAdmin::Config::Actions.register(self)

            register_instance_option :member? do
              true
            end

            register_instance_option :http_methods do
              [:get, :put]
            end

            register_instance_option :visible? do
              authorized? && (['Painting'].include? bindings[:abstract_model].model.to_s)
            end

            register_instance_option :bulkable? do
              false
            end

            register_instance_option :pjax? do
              true
            end


            register_instance_option :controller do
              Proc.new do
                if request.get? # show crop page
                  respond_to do |format|
                    format.html { render @action.template_name }
                    format.js   { render @action.template_name, :layout => false }
                  end
                elsif request.put? # Submit
                  Rails.logger.warn "\n=========================\n"
                  Rails.logger.warn @object.inspect

                  @object.image.recreate_versions!
                  flash[:notice] = "#{@object.title} successfully cropped."
                  redirect_to "/admin/#{@abstract_model.to_s.downcase}"
                end
              end
            end


            register_instance_option :link_icon do
              'icon-th-large'
            end

          end
        end
      end
    end

这是我的 Rails 管理路由(它们似乎没有向我现有的任何操作添加路由,所以这些只是默认路由):

    Routes for RailsAdmin::Engine:
        dashboard GET         /                                      rails_admin/main#dashboard
            index GET|POST    /:model_name(.:format)                 rails_admin/main#index
              new GET|POST    /:model_name/new(.:format)             rails_admin/main#new
           export GET|POST    /:model_name/export(.:format)          rails_admin/main#export
      bulk_delete POST|DELETE /:model_name/bulk_delete(.:format)     rails_admin/main#bulk_delete
    history_index GET         /:model_name/history(.:format)         rails_admin/main#history_index
      bulk_action POST        /:model_name/bulk_action(.:format)     rails_admin/main#bulk_action
             show GET         /:model_name/:id(.:format)             rails_admin/main#show
             edit GET|PUT     /:model_name/:id/edit(.:format)        rails_admin/main#edit
           delete GET|DELETE  /:model_name/:id/delete(.:format)      rails_admin/main#delete
     history_show GET         /:model_name/:id/history(.:format)     rails_admin/main#history_show
      show_in_app GET         /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app
4

0 回答 0