Ruby 林务署署长:";无效的数据URI:nil";当我尝试构建导入数据自定义操作时
我是RoR的初学者,我想在forest admin for import data(csv)中实现一个自定义操作。 我有我的动作控制器(controllers/forest/actions\u controller.rb): 我加上我的路线:Ruby 林务署署长:";无效的数据URI:nil";当我尝试构建导入数据自定义操作时,ruby,ruby-on-rails-4,rubygems,data-uri,forestadmin,Ruby,Ruby On Rails 4,Rubygems,Data Uri,Forestadmin,我是RoR的初学者,我想在forest admin for import data(csv)中实现一个自定义操作。 我有我的动作控制器(controllers/forest/actions\u controller.rb): 我加上我的路线: namespace :forest do post '/actions/bulk_import' => 'actions#bulk_import' end 这不管用…:/ 消息错误: Started OPTIONS "/forest/acti
namespace :forest do
post '/actions/bulk_import' => 'actions#bulk_import'
end
这不管用…:/
消息错误:
Started OPTIONS "/forest/actions/bulk_import" for 127.0.0.1 at 2017-08-19 18:52:30 +0200
Started POST "/forest/actions/bulk_import" for 127.0.0.1 at 2017-08-19 18:52:30 +0200
Processing by Forest::ActionsController#bulk_import as HTML
Parameters: {"data"=>{"attributes"=>{"ids"=>[], "values"=>{"importer csv"=>"data:text/csv;base64,77u/ZGVwYXJ0ZW1lbnQsIHNsdWcsIG5vbSwgbm9tX3NpbXBsZQ0iMSwiIjAxIiIsIiJvemFuIiIsIiJPWkFOIiIi"}, "collection_name"=>"geos"}, "type"=>"custom-action-requests"}}
Completed 500 Internal Server Error in 3ms (ActiveRecord: 0.0ms)
URI::InvalidURIError - Invalid Data URI: nil:
data_uri (0.1.0) lib/data_uri/uri.rb:15:in `initialize'
app/controllers/forest/actions_controller.rb:4:in `bulk_import'
快速建议写入
在类名上方需要“data\u uri”
。快速建议写入在类名上方需要“data\u uri”
。在您的配置中,字段名为导入器csv
,因此请求中将发送此字段名
在lib/forest\u liana/collections/geo.rb中
在控制器中,您应该执行以下操作:
uri = URI::Data.new(params.dig('data', 'attributes', 'values', 'importer csv'))
而不是:
uri = URI::Data.new(params.dig('data', 'attributes', 'values', 'file'))
看起来,
importer csv
应该是操作的名称,而不是字段
如果您想这样命名您的操作,以下是合适的配置:
在您的配置中,字段名为
importer csv
,因此将在请求中发送此字段名
在lib/forest\u liana/collections/geo.rb中
在控制器中,您应该执行以下操作:
uri = URI::Data.new(params.dig('data', 'attributes', 'values', 'importer csv'))
而不是:
uri = URI::Data.new(params.dig('data', 'attributes', 'values', 'file'))
看起来,
importer csv
应该是操作的名称,而不是字段
如果您想这样命名您的操作,以下是合适的配置:
uri = URI::Data.new(params.dig('data', 'attributes', 'values', 'file'))
class Forest::Geo
include ForestLiana::Collection
collection :geos
action 'Importer CSV', global: true,
fields: [{
field: 'importer csv', type: 'File', isRequired: true, description: "Personal description",
}]
end