在我的Rails 3.2.13应用程序中,有一个导入联系页面,我们可以通过csv导入联系人,如果缺少任何字段或映射,我们可以手动映射标题。为此,他们使用了map_fields插件,其中大部分代码都是公开的 - >插件文件夹。 现在,当我尝试在4.2.6应用程序中运行相同时,这是我面临的错误:
LoadError - 无法加载此类文件 - map_fields:activesupport (4.2.6)lib / active_support / dependencies.rb:274:在
中block in require'
块中 在load_dependency'activesupport(4.2.6)中 lib / active_support / dependencies.rb:647:in
activesupport (4.2.6) lib/active_support/dependencies.rb:238:innew_constants_in'
load_dependency'activesupport(4.2.6) lib / active_support / dependencies.rb:274:在
activesupport (4.2.6) lib/active_support/dependencies.rb:238:inrequire'
'中 app / controllers / contacts_controller.rb:1:在
app/controllers/contacts_controller.rb:2:in<top (required)>'
块中 在load_file'activesupport(4.2.6)中 lib / active_support / dependencies.rb:647:in
activesupport (4.2.6) lib/active_support/dependencies.rb:457:innew_constants_in'
load_file'activesupport(4.2.6) lib / active_support / dependencies.rb:354:in
activesupport (4.2.6) lib/active_support/dependencies.rb:456:inrequire_or_load'
load_missing_constant'activesupport(4.2.6) lib / active_support / dependencies.rb:184:在`const_missing'
activesupport (4.2.6) lib/active_support/dependencies.rb:494:in
这是我的控制者:
class ContactsController < ApplicationController
require 'map_fields'
map_fields :mapper, ['First Name','Last Name', 'Email', 'Notes'], :file_field => :file, :params => [:contact]
def create
@user = User.find(params[:user_id])
@contact = @user.contacts.create(contact_params)
respond_to do |format|
if @contact.save
format.json { render :json => { :notice => 'Contact was successfully created!',:redirect => user_contacts_url} }
format.html { redirect_to(user_contacts_url(@user), :notice => 'Contact was successfully created!', :type => 'success') }
else
format.json { render :json => {:redirect => false} }
format.html { render :action => "edit" }
end
end
end
def import
@contact = Contact.new
end
def mapper
@contact = Contact.new(params[:contact])
count = 0
if fields_mapped?
mapped_fields.each do |row|
params[:contact] = {"user_id" => @current_user.id, "firstname" => row[0], "lastname" => row[1], "notes" => row[3], "email" => row[2].try(:strip)}
contact = Contact.new(params[:contact])
if contact.save
count = count + 1
end
end
if count > 0
flash[:notice] = "#{count} Contact(s) created"
redirect_to :action => :index
else
flash[:notice] = "No contact was created..."
redirect_to :action => :index
end
else
@best_row = @rows[1]
render
end
rescue MapFields::InconsistentStateError
flash[:error] = 'Please try again'
redirect_to :action => :import
rescue MapFields::MissingFileContentsError
flash[:error] = 'Please upload a file'
redirect_to :action => :import
end
end
除此之外,我有联系人/ import.html.erb:
<%= semantic_form_for :contact, :url => mapper_user_contacts_path do |f| %>
<%= f.inputs :name => 'Please select a CSV file to upload' do %>
<%= f.input :file, :label => false, :as => :file, :input_html => {:name => "file", :id => "file"} %>
<% end %>
<%= f.buttons do %>
<%= f.commit_button raw('Import contacts') %>
<% end %>
<% end %>
和app / views / contacts / mapper.html.erb:
<%= render :partial => 'map_fields/map_fields' %>
以上呈现字段位于供应商中 - &gt;插件 - &gt; map_fields文件夹。
请帮助我如何克服错误?是否从插件文件夹中呈现数据?