Hi Guys,

I am using import CSV to import from a csv file to my database in my
rails app. I want to be able to be able to add a list of email
addresses from this file but also include the mailinglist_id which is
a param[:id] on my page in the database entry. So in effect adding a
csv of emails to any mailing list.

I am just a little unclear as to how I add the extra field when adding
the data to the database.... any help would be great!!

Database table "mailings" is as follows...

mailinglist_id, id, name, email_address

-----------------------------------------------------------------------------------------------------------------------------
import_csv controller

 def csv_import
      file = params[:csv_import][:file]
      logcount=0
      Mailing.transaction do
        FasterCSV.parse(file, :headers => true) do |row|
          Mailing.create!(row.to_hash)
          logcount += 1
        end
      end
      flash[:notice] = "Successfully imported #{logcount} email(s)
from mailing list."
      redirect_to :action => :index
    rescue => exception
      # If an exception is thrown, the transaction rolls back and we
end up in this rescue block
      error = ERB::Util.h(exception.to_s) # get the error and HTML
escape it
      flash[:error] = "Error adding list.  (#{error}).  Please try
again."
      redirect_to :action => :index
    end
-----------------------------------------------------------------------------------------------------------------------------

index.html.erb

<% form_for :csv_import, :url=>{ :controller=>"import_csv", :action =>
'csv_import'},
:html => { :multipart => true } do |f| %>
        <p>
                <%= f.label :file, 'Import mail list file' %><br/>
                <%= f.file_field :file -%>
        </p>
        <p>
                <%= submit_tag "Submit" %>
        </p>
<% end %>

-------------------------------------------------------------------------------------------------------------------------------


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to