Topic: Send email when submit a form wihout DB


I try to setup a send email when we submit a form.
The form don't have table. its only a popup window with email and a textarea for the mail content.

i tried this … ample.html

but it's not exacly what i'm looking for because i'm in a model (action => show)  with a jquery dialog.

what i'm looking is to create a mail with attached file from the current models and some informations.

for now i have do :

rails g mailer notifier

rails g resource sendmail

i have created my form (not for form for now beccause i don't want db for my sendmail.

Any idea how can i do that?


Re: Send email when submit a form wihout DB

You can use after_validation callback or send email in controller

For first

after_validation :send_mail


  def send_mail

in cotroller

if support.valid?

method save better delete from code

Last edited by jalkoby (2011-09-02 17:00:56)

Re: Send email when submit a form wihout DB

Thanks for you replay.

The problem is more in the form. Because the my send email controller has no db. How can i handle the form?

I tried with form_tag and form_for, both don't look to works.

the problem i have is

i'm in a controller view :show, i created a new controller to manage my send email.

here is a best example


in my books show page, i have a link to email current book information and some doc attachment.

i know how to manage attached files.

but i really dont know how to create form wihout db field like : fromemail, toemail, note, etc...

Thanks for your help.

Re: Send email when submit a form wihout DB

I have finally setted up my form.

the problem is when i submit it.
i get this error .

here is my models/views/controller

def plan_notification(resource)
   @plans = resource
   mail(:to => "maskedemail",
      :from => 'maskedemail',
      :subject => 'test')

def save

and my controller
def send

  puts 'test'
  @emailplan =[:emailplan])

my routes.rb
match 'emailplans/send' => 'emailplans#send', :as => :send_emailplan

my form

<%= form_for @emailplan, :as => :emailplans, :url => send_emailplan_path do |e| %>
    <div>To : <%= e.text_field 'toemail' %></div>
    <div>From : <%= e.text_field 'fromemail' %></div>
    <div>Note : </div>
    <div><%= e.text_area 'note', :rows => 5 %></div>
    <div><%= e.submit 'Send plans' %></div>
<% end %>

and i get this error

Parameters: {"commit"=>"Send plans", "authenticity_token"=>"12dR2T8IOSoKktQEHxthP8v5bxTuPBzwnoWz9lTgim0=", "utf8"=>"✓", "emailplans"=>{"fromemail"=>"maskedemail", "toemail"=>"maskedemail", "note"=>"23423423"}}
Completed 500 Internal Server Error in 0ms

ArgumentError (wrong number of arguments (2 for 0)):

how to set the number or arguments?


Last edited by neimad (2011-09-05 09:57:12)