虽然我在其他博客中看到了这个问题,但我无法在我的案例中使用它。 我的观点:
<%= 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%>
我的控制器:
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
我收到此错误:nil的未定义方法`original_filename':我的控制器中的NilClass并且我不知道如何修复它,任何帮助都将不胜感激,谢谢!
答案 0 :(得分:1)
您已拨打original_filename
3次,删除了两个original_filename
,它将起作用:
collection_action :status_race, :method => :post do
uploaded_io = params[:uploaded_data].original_filename
File.open(Rails.root.join('app/importers', 'uploads', uploaded_io), 'w') do |file|
file.write(uploaded_io.read)
end
RoutesQuickcom.new.run(uploaded_io)
render "status_race"
end