I'm trying to create a file upload script using RoR but I am getting
"You have a nil object when you didn't expect it!" and I think this is
caused by the fact that the no form has been submitted. Is that
right?
I'm trying to create a file upload script using RoR but I am getting
"You have a nil object when you didn't expect it!" and I think this is
caused by the fact that the no form has been submitted. Is that
right?
Maybe, maybe not. The error message should tell you what line the
error occurred on, then you need to go and look at that line of code
and work out what's wrong. Also look at the params hash being submitted.
You can use this to ignore the file, before submission (controller):
unless params[:file].nil?
And this is the correct code for the view:
<% form_tag({:action=> "parse_csv"}, {:multipart => true}) do %>
<table>
<tr>
<label for="dump_file">
<td><b><i>Select a CSV File: </i></b></td>
</label>
<td><%= file_field_tag 'file' %></td>
</tr>
<tr>
<td colspan='2'><%= submit_tag "Submit" %></td>
</tr>
</table>
<% end %>
Note that the file is referenced as: params[:file]