Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 无法加载这样的文件--映射\u字段_Ruby On Rails - Fatal编程技术网

Ruby on rails 无法加载这样的文件--映射\u字段

Ruby on rails 无法加载这样的文件--映射\u字段,ruby-on-rails,Ruby On Rails,在我的Rails 3.2.13应用程序中,有一个导入联系人页面,我们可以通过csv导入联系人,如果缺少任何字段或映射,我们可以使用标题手动映射。为此,他们使用了map_fields插件,其中大部分代码位于public->plugins文件夹中。 现在,当我尝试在4.2.6应用程序中运行相同的程序时,我面临的错误是: LoadError-无法加载此类文件--映射\u字段:activesupport (4.2.6)lib/active_支持/依赖项。rb:274:inblock in require

在我的Rails 3.2.13应用程序中,有一个导入联系人页面,我们可以通过csv导入联系人,如果缺少任何字段或映射,我们可以使用标题手动映射。为此,他们使用了map_fields插件,其中大部分代码位于public->plugins文件夹中。 现在,当我尝试在4.2.6应用程序中运行相同的程序时,我面临的错误是:

LoadError-无法加载此类文件--映射\u字段:activesupport (4.2.6)lib/active_支持/依赖项。rb:274:in
block in require'
activesupport(4.2.6)lib/active_support/dependencies.rb:238:in
block 在load_dependency的activesupport中(4.2.6) lib/active\u support/dependencies.rb:647:in
new\u constants\u in'
activesupport(4.2.6)lib/active_support/dependencies.rb:238:in
load_dependency'activesupport(4.2.6) lib/active\u支持/依赖项。rb:274:in
require'
app/controllers/contacts_controller.rb:2:in

app/controllers/contacts_controller.rb:1:in

activesupport(4.2.6)lib/active\u支持/依赖项。rb:457:in
块 在加载文件“activesupport”(4.2.6)中 lib/active\u support/dependencies.rb:647:in
new\u constants\u in'
activesupport(4.2.6)lib/active\u support/dependencies.rb:456:in
load_file'activesupport(4.2.6) lib/active\u支持/依赖项。rb:354:in
require\u或\u load'
activesupport(4.2.6)lib/active\u support/dependencies.rb:494:in
load\u missing\u constant'activesupport(4.2.6) lib/active\u support/dependencies.rb:184:in'const\u missing'

这是我的控制器:

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
class contacts控制器:file、:params=>[:contact]
def创建
@user=user.find(参数[:user\u id])
@contact=@user.contacts.create(contact_参数)
回应待办事项|格式|
如果@contact.save
format.json{render:json=>{:notice=>'联系人已成功创建!',:redirect=>user\u contacts\u url}
format.html{redirect_to(user_contacts_url(@user),:notice=>“联系人已成功创建!”,:type=>“success”)}
其他的
format.json{render:json=>{:redirect=>false}
format.html{render:action=>“edit”}
结束
结束
结束
def导入
@contact=contact.new
结束
def映射器
@联系人=联系人。新建(参数[:联系人])
计数=0
如果字段被映射?
映射的_字段。每个do|行|
参数[:contact]={“user\u id”=>@current\u user.id,“firstname”=>行[0],“lastname”=>行[1],“notes”=>行[3],“email”=>行[2]。请尝试(:strip)}
联系人=联系人。新建(参数[:联系人])
如果联系。保存
计数=计数+1
结束
结束
如果计数>0
flash[:注意]=“创建了#{count}个联系人”
将_重定向到:action=>:index
其他的
flash[:notice]=“未创建联系人…”
将_重定向到:action=>:index
结束
其他的
@最佳行=@行[1]
提供
结束
rescue映射字段::不一致状态错误
flash[:错误]=“请重试”
将_重定向到:操作=>:导入
rescue映射字段::缺少文件内容错误
flash[:error]=“请上传文件”
将_重定向到:操作=>:导入
结束
结束
除此之外,我还有联系人/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 %>
<%= render :partial => 'map_fields/map_fields' %>
mapper_user_contacts_path do|f|%>
'请选择要上载的CSV文件'do%>
false,:as=>:file,:input_html=>{:name=>“file”,:id=>“file”}%>
和app/views/contacts/mapper.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 %>
<%= render :partial => 'map_fields/map_fields' %>
“映射字段/映射字段”%>
上述渲染字段位于供应商->插件->映射字段文件夹中


请帮助我如何克服这个错误?数据是从插件文件夹中呈现的吗?

我认为您的错误来自控制器中的
要求“映射字段”
。您应该有此文件的源。也许,你的Rails没有看到供应商->插件->地图字段文件夹。我做了一些研发,地图字段可以从gem和插件安装。在我的版本中,他们使用了插件。Rails中的插件应该在Rails的更高版本中删除,所以用gem替换它。是否有任何gem可以导入联系人,如果标题不匹配,我们可以自动匹配?这篇文章可能会有所帮助:我想你的错误来自controller中的
要求“映射字段”
。您应该有此文件的源。也许,你的Rails没有看到供应商->插件->地图字段文件夹。我做了一些研发,地图字段可以从gem和插件安装。在我的版本中,他们使用了插件。Rails中的插件应该在Rails的更高版本中被删除,所以用gem替换它。是否有任何gem可以导入联系人,如果标题不匹配,我们可以自动匹配?这篇文章可能会有帮助: