Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:29:43+00:00 2026-06-18T03:29:43+00:00

I am following the Import CSV Railscast and it is straight forward. I added

  • 0

I am following the Import CSV Railscast and it is straight forward.

I added require 'csv' to my config/application.rb

In my BuildingsController I created a new import action like so:

def import
  Building.import(params[:file])
  redirect_to root_url, notice: "Buildings imported."
end

In my view, I have this:

<h2>Import Buildings</h2>
<%= form_tag import_buildings_path, multipart: true do %>
  <%= file_field_tag :file %>
  <%= submit_tag "Import" %>
<% end %>

This is in my Building.rb model:

def self.import(file)
  CSV.foreach(file.path, headers: true) do |row|
    building = find_by_name(row["name"]) || new
    building.attributes = row.to_hash.slice(*accessible_attributes)
    building.save!
  end
end

In my routes.rb, I have this:

  resources :buildings do
    collection { post :import }
  end

When I click the ‘import’ button on my view, I get this error:

NoMethodError at /buildings/import

Message undefined method `path' for nil:NilClass
File    /myapp/app/models/building.rb
Line    23

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:29:44+00:00Added an answer on June 18, 2026 at 3:29 am

    From the comment: You are most probably submitting the form without choosing a file 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following the Import CSV Railscast and it is straight forward. The issue
I like to write a cmdlet Convert-ToHashTable which performs following task: $HashTable = Import-Csv
I have the following snippet of code: import csv def has_header(first_lines): sniffer = csv.Sniffer()
I have the following admin action below that exports data to a CSV file,
I have the following scenario: I have to import a CSV file to a
I'm trying to import data from a csv file following the example given by
I'm overriding the csv.Dictreader.fieldnames property like the following to read all headers from csv
Im using the following code to import a csv that has two columns -
I got the following code (working): #Import File $Users = Import-Csv C:\Users\Administrator\Desktop\userImport\users.csv # Setting
I tried to import csv file data into postgres table. Running the following line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.