Hi Guys,
I have a mail_templates table
I have a mailinglists table
I have a mail_templates_mailinglists table with mailtemplate_id, and
mailinglist_id
mail_template has_and_belongs_to_many :mailinglists
mailinglist has_and_belongs_to_many :mail_templates, :foreign_key =>
“mailinglist_id”
I want to be able to stop the user being able to destroy the
mail_template if it is being used by a mailinglist.
So in my destroy method in my mail_template controller I want to find
any mailinglists that have a mail_template id.
I tried the following but I am getting an error,
mailinglist = Mailinglist.mail_template_mailinglists.find(:all,
:conditions => ["mail_template_id = ?", params[:id]])
if mailinglist.empty?
MailTemplate.find(params[:id]).destroy
else
flash[:notice] = 'Cannot delete mail template, as it is being used
by one or more mailinglist.’
end
NoMethodError in Admin/mail templatesController#destroy
undefined method `mail_template_mailinglists’ for #Class:0x3333814