Hi,
i implemented the task of importing data from csv into MySQL database
successfully. Now, my requirement is: i need to get error message with
line number, if there is any mis match of data in csv file while
importing.
This is my controller code:
require 'csv' #at the top and followed by...
def load_csv
# no code
end
def import_csv
parsed_file = CSV.foreach(params[:csv].tempfile,:headers => true) do
|row|
row = row.to_hash.with_indifferent_access
Institute.create!(row.to_hash.symbolize_keys)
redirect_to :action => :index
end
In my view/ load_csv.html.erb:
<%= form_for(:institute, :url => import_csv_institutes_path, :html =>
{:multipart => true}) do |f| %>
<div class="field">
<%= file_field_tag :csv %>
<%= f.submit 'Import' %>
</div>
<% end %>
In config/route.rb:
resources :institutes do
get 'load_csv', :on => :collection
post 'import_csv', :on => :collection
end
I tried for flash message before redirect_to :action => :index in
import_csv, but its of no use.. TH eflash is not working.
The above are the only three steps i used for importing. Model
validations are working only for form and for csv, an error page
displayed.. Please try to help me out.........................
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.