Skip to content

No such file to load -- map_fields in Rails 4.2 #6

@rajosi

Description

@rajosi

I upgraded my Rails version from 3.2.13 to Rails 4.2.6. In the older version, they used map_fields plugin where in my contacts controller:

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

when I run the code I am getting the error

ActionController::RoutingError - undefined method write_inheritable_attribute' for ContactsController:Class: actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:63:inrescue in controller'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:58:in controller' actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:39:inserve'
actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in block in serve' actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:inserve'
actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in call' meta_request (0.4.0) lib/meta_request/middlewares/app_request_handler.rb:13:incall'
meta_request (0.4.0) lib/meta_request/middlewares/meta_request_handler.rb:13:in call' warden (1.2.6) lib/warden/manager.rb:35:inblock in call'
warden (1.2.6) lib/warden/manager.rb:34:in call' client_side_validations (4.2.5) lib/client_side_validations/middleware.rb:15:incall'
rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4) lib/rack/conditionalget.rb:25:incall'
rack (1.6.4) lib/rack/head.rb:13:in call' remotipart (1.2.1) lib/remotipart/middleware.rb:27:incall'
actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in call' actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:incall'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in context' rack (1.6.4) lib/rack/session/abstract/id.rb:220:incall'
actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in call' activerecord (4.2.6) lib/active_record/query_cache.rb:36:incall'
activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in call' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
activesupport (4.2.6) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.6) lib/active_support/callbacks.rb:778:in_run_call_callbacks'
activesupport (4.2.6) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:incall'
rails-dev-tweaks (1.2.0) lib/rails_dev_tweaks/granular_autoload/middleware.rb:36:in call' actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:incall'
airbrake (4.3.8) lib/airbrake/rails/middleware.rb:13:in call' better_errors (2.1.1) lib/better_errors/middleware.rb:84:inprotected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in better_errors_call' better_errors (2.1.1) lib/better_errors/middleware.rb:57:incall'
actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' rack-contrib (1.4.0) lib/rack/contrib/response_headers.rb:17:incall'
meta_request (0.4.0) lib/meta_request/middlewares/headers.rb:16:in call' actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:incall'
railties (4.2.6) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.6) lib/rails/rack/logger.rb:20:inblock in call'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:intagged'
activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.6) lib/rails/rack/logger.rb:20:incall'
actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.6.4) lib/rack/methodoverride.rb:22:incall'
rack (1.6.4) lib/rack/runtime.rb:18:in call' activesupport (4.2.6) lib/active_support/cache/strategy/local_cache_middleware.rb:28:incall'
rack (1.6.4) lib/rack/lock.rb:17:in call' actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:incall'
rack (1.6.4) lib/rack/sendfile.rb:113:in call' airbrake (4.3.8) lib/airbrake/user_informer.rb:16:in_call'
airbrake (4.3.8) lib/airbrake/user_informer.rb:12:in call' railties (4.2.6) lib/rails/engine.rb:518:incall'
railties (4.2.6) lib/rails/application.rb:165:in call' rack (1.6.4) lib/rack/content_length.rb:15:incall'
thin (1.5.1) lib/thin/connection.rb:81:in block in pre_process' thin (1.5.1) lib/thin/connection.rb:79:inpre_process'
thin (1.5.1) lib/thin/connection.rb:54:in process' thin (1.5.1) lib/thin/connection.rb:39:inreceive_data'
eventmachine (1.0.9.1) lib/eventmachine.rb:193:in run' thin (1.5.1) lib/thin/backends/base.rb:63:instart'
thin (1.5.1) lib/thin/server.rb:159:in start' rack (1.6.4) lib/rack/handler/thin.rb:19:inrun'
rack (1.6.4) lib/rack/server.rb:286:in start' railties (4.2.6) lib/rails/commands/server.rb:80:instart'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:80:in block in server' railties (4.2.6) lib/rails/commands/commands_tasks.rb:75:inserver'
railties (4.2.6) lib/rails/commands/commands_tasks.rb:39:in run_command!' railties (4.2.6) lib/rails/commands.rb:17:in<top (required)>'
bin/rails:4:in `

'

This is my routes.rb file:

Htm::Application.routes.draw do
  .......................other routes......
  resources :contacts do
      post :import_remote,  :on => :collection
      get :import_remote,   :on => :collection
      collection  do
        post    :mapper
        get     :import
        post    :destroy_multiple
        delete  :destroy_all
      end
    end
end

I followed the same steps you given in issue 1, but I am getting this error. Please help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions