1

I am creating an app that has an option to add single entries to a database model as well as upload multiple from an Excel doc. I am following the rails guides on uploading and am hoping there is a way to utilize the RubyXL gem to upload the Excel doc. Below are the relevant docs:

revenue_models/upload.html.erb

You are in the Upload view...
<%= form_for(@uploaded_doc, :url => {:action => parse_upload_revenue_models_path}, :html => {:method => "put"}) do |f| %>
    <%= f.file_field(:workbook) %>
    <%= f.submit("Upload File") %>                                                   
<% end %> 

routes.rb

Dataway::Application.routes.draw do
    devise_for :users
    resources :revenue_models do
        get 'upload', :on => :collection         
    end
    match 'revenue_models/upload' => 'revenue_models#parse_upload', :via => :post
    root :to => "home#index"
end

revenue_models_controller.rb

...
def upload
    @uploaded_doc = { :workbook => RubyXL::Parser.new }
end
def parse_upload
    @worksheet = (params[:uploaded_doc])
    @worksheet_name = @worksheet.original_filename
end

The revenue_models model is the database that will ultimately be modified with the parsed data from the excel doc. The model does not contain a column for the uploaded doc. I have the form in the upload.html.erb view routing to the parse_upload action. However, I am getting the following error:

NoMethodError in Revenue_models#upload
    undefined method `model_name' for NilClass:Class

The error has something to do with the form_for in the upload.html.erb view. Please help.

Utopia025
  • 1,181
  • 3
  • 11
  • 21

0 Answers0