Hi--
On May 4, 2009, at 2:38 PM, doug wrote:

> I have a mailing-list database that consists of several tables (e.g.,
> clients table, prospects table, etc.).  How can I switch between these
> tables within my mailing-list Rails application?
>
> I have a feeling that if I better understood the role of the model I
> might be able to answer my own question.  I'm hoping that getting this
> question answered will help me in that regard.

In Rails, a model normally maps to a table. So if you have a clients  
table, you have a Client model and if your have a prospects table, you  
have a Prospect model. Rails infers the table name and columns from  
the name of the model class. So you can do:

send_email_to :clients
send_email_to :prospects

def send_email_to(whom)
   model = whom.to_s.camelize.constantize.all.each do |recipient|
     # recipient is an object of the specified type. Send email at will!
   end
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 [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
-~----------~----~----~----~------~----~------~--~---

Reply via email to