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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 12, '12 at 7:40a
activeApr 12, '12 at 7:40a
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

RAJ K.: 1 post

People

Translate

site design / logo © 2021 Grokbase