I’m new to Ruby on Rails, trying to get my first app working, which involves uploading a CSV file, then parsing the data into tables.
Found a great tutorial about uploading CSV here, but when I try it, I get the following error:
‘Called id for nil, which would mistakenly be 4…’
which, I’m sure, is because I’m making some simple error in the following code:
> <h2>Upload a CSV file to import into the database</h2>
> <% form_for @import, :html => { :multipart => true } do |f| %>
> <%= f.file_field :csv %>
> <select name="import[datatype]" size="1">
> <option value="releases"> Press Releases </option>
> </select>
> <%= f.submit "Import" %>
> <% end %> <%= link_to 'Back', genotypes_path %>
This happens when loading my app page http://localhost:3000/genotypes/new.
I’m using Ruby 1.8.7, Rail 2.1.0.
Does anyone see what I’m doing wrong here?
TIA,
–rick
The most likely culprit is that you’re not setting @import in the controller. This is a common error message that points to a nil object being used somewhere. in your case, its probably the form_for that’s causing you problems, because form_for is going to look for the id on the object its given to know whether to submit the form to the update action or the create action. If that object is nil, #id references its object_id, not its database primary key; hence the somewhat cryptic error message.