Jquery 我得到一个错误:缺少模板,有许多重复的不存在的操作 有什么问题吗?
在rails 4.2.5.1中,我做了一个导入csv的操作。对于这一个,我使用,我将用这个上传的csv更新记录。我的记录被成功更新了。但问题是在那之后 更新记录后,我想重新加载页面。但错误是不存在的Jquery 我得到一个错误:缺少模板,有许多重复的不存在的操作 有什么问题吗?,jquery,ruby-on-rails,csv,Jquery,Ruby On Rails,Csv,在rails 4.2.5.1中,我做了一个导入csv的操作。对于这一个,我使用,我将用这个上传的csv更新记录。我的记录被成功更新了。但问题是在那之后 更新记录后,我想重新加载页面。但错误是不存在的 (1.1ms) COMMIT System Load (0.5ms) SELECT "systems".* FROM "systems" ORDER BY "systems"."id" DESC LIMIT 1
(1.1ms) COMMIT
System Load (0.5ms) SELECT "systems".* FROM "systems" ORDER BY "systems"."id" DESC LIMIT 1
Completed 500 Internal Server Error in 3622ms (ActiveRecord: 2.6ms)
ActionView::MissingTemplate - Missing template systems/import, application/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import, smart_listing/import with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
* "/Users/Penguin/Desktop/Dev_Web/chartTest/app/views"
* "/Users/Penguin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/kaminari-0.16.3/app/views"
* "/Users/Penguin/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/smart_listing-1.1.2/app/views"
:
actionview (4.2.5.1) lib/action_view/path_set.rb:46:in `find'
actionview (4.2.5.1) lib/action_view/lookup_context.rb:121:in `find'
actionview (4.2.5.1) lib/action_view/renderer/abstract_renderer.rb:18:in `find_template'
您可以看到许多重复的智能\u列表/导入
。以及系统/导入
应用程序/导入
。但这些都是不存在的方法。所以我想我犯了一些错误。是什么导致了这个恼人的错误?谢谢
代码
#routes.rb
资源:系统可以
获取'export',操作:'export',on::collection,默认值:{format:'csv'}
将“导入”操作“导入”放在::集合上
修补程序“导入”,操作:“导入”,在::集合上
结束
#system.rb
类系统
将位置:索引更改为位置:url\u for(action::index)
。您正在这里显式执行索引操作。@BroiSatse Nope。没有任何改变。输出了相同的错误。能否从日志中提供更多上下文?似乎您正在发送json
请求,而您的控制器正在尝试查找您没有的index.json
模板。你想在那里实现什么样的行为?
#routes.rb
resources :systems do
get 'export', action: 'export', on: :collection, defaults: { format: 'csv'}
put 'import', action: 'import', on: :collection
patch 'import', action: 'import', on: :collection
end
# system.rb
class System < ActiveRecord::Base
def self.import_csv(setting)
CSV.foreach(setting.path, headers: true) do |row|
if System.new(row.to_hash).valid?
System.last.update(row.to_hash)
return true
else
return false
end
end
end
end
# system_controller.rb
class SystemsController < ApplicationController
def import
respond_to do |format|
if System.import_csv(params[:setting])
format.html { redirect_to action: :index, notice: 'Home was successfully updated.' }
format.json { render :import, status: :ok, location: index }
else
format.html { render :import }
format.json { render status: :bad_request}
end
end
end
end
<!-- systems/index.html.erb -->
<%= form_tag import_systems_path, multipart: true, id: 'import' do %>
<div class="btn btn-lightDarkTwt" id="setting-import">
<span class="glyphicon glyphicon-import"></span>
<span>export</span>
<%= file_field_tag :setting %>
</div>
<% end %>
// system.js
$(document).ready(function() {
$('input#setting').fileupload({
url: location.href + '/import',
dataType: 'json',
type: 'put',
autoUpdate: true,
add: function(e, data) {
data.submit();
}
})
})