RAJ K.
2012-Apr-12 07:40 UTC
Validations for Importing CSV data into MySql database in Rails 3.1?
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.