undefined method `original_filename' for nil:NilClass

327 views
Skip to first unread message

Anna

unread,
Nov 12, 2012, 8:40:30 AM11/12/12
to rubyonra...@googlegroups.com
Hi, although I saw this problem in other blogs, I couldn't make it works.
My view:
<%= semantic_form_for :routes_status_race, :url => status_race_admin_routes_path do |f| %>
<% contact_array = Contact.all.map {|contact| [contact.name, contact.id]}%>
  <% route_importer_array = RouteImporter.all.map {|importer| [importer.name, importer.id]}%>
  <%= f.inputs do%>
  <%= f.input :contact, :as => :select, :collection => Contact.all %>
  <%= f.input :route_import, :as => :select, :collection => RouteImporter.all %>
        <%= f.input :uploaded_data, :action => :status_race, :multipart => true, :as => :file %>
  <%end%>
  <input name='commit' type='submit' method='post' value='Import'/>
<%end%>

My controller:

 collection_action :status_race, :method => :post do

    uploaded_io = params[:uploaded_data].original_filename

    File.open(Rails.root.join('app/importers', 'uploads', uploaded_io.original_filename), 'w') do |file|
      file.write(uploaded_io.read)
    end

    RoutesQuickcom.new.run(uploaded_io.original_filename)
    render "status_race"
  end
end

I don't know how to fix it , any help will be appreciate, thanks!

Anna

unread,
Nov 12, 2012, 9:32:28 AM11/12/12
to rubyonra...@googlegroups.com
Now is solved, just in case that somebody will has the same problem, here is the solution, the view was right, I just change the controller part:

collection_action :status_race, :method => :post do

    uploaded_io = params[:routes_status_race][:uploaded_data]

    File.open(Rails.root.join('app/importers', 'uploads', uploaded_io.original_filename), 'w') do |file|
      file.write(uploaded_io.read)
    end
    RoutesQuickcom.new()
    render "status_race"
  end
Reply all
Reply to author
Forward
0 new messages