0

I have a model that has some attached files. In the show action, I have a link to open a dialog that shows a form.

This form is for sending email with the attached files from the parent models, as well as some information about the model.

I created a generator:

rails g mailer notifier
rails g resource emailsystem

For now, i have a div in the show

<div id="dialog" style="display:none">
  <%= form_for ???? do |f| %>
      <%= f.text_field :fromemail %>
  <% end %>
</div>

But I don't know with what model i need to attach this form, because the form doesn't need a db. I have created a new resource, but when I use it, I get an error because the resource table doesn't exist.

How I can do that? I think I need to attach the dialog form with the current model.

EDIT ------------

Now i have created my form and controller and mailer + models

mailer + models 

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

model
def save
    Emailplan.plan_notification(self).deliver!
end

and my controller

def send

  puts 'test'
  @emailplan = Emailplan.save(params[:emailplan])
end


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 %>

but with all that, 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)):

Why i have wrong number of arguments? Where i can set the number of arguments for my models/controller?

Thanks.

neimad
  • 219
  • 1
  • 5
  • 20

1 Answers1

0

The short answer is use form_tag instead of form_for. So:

<%= form_tag '/url/to/controller/that/sends/mail/goes/here' do |f| %>
  <%= f.text_field 'fromemail' %>
  <%= f.submit 'Send email' %>
<%= end %>

The longer answer is you may want to read a tutorial or two on actionmailer - I suspect you might be a little confused about how mail works in rails(?) ;-)

Documentation here: http://api.rubyonrails.org/classes/ActionMailer/Base.html

or if you prefer, the RailsCast: http://railscasts.com/episodes/206-action-mailer-in-rails-3

PlankTon
  • 12,443
  • 16
  • 84
  • 153
  • yeah i'm a bit confuse to use the actionmailer hehe thanks for the links, i have already checked video on railscasts. thanks. – neimad Sep 02 '11 at 19:57
  • unclaimedbaggage, your way of using the text_field don't look to work, i get this error message : 'undefined method `text_field' for nil:NilClass' if i change some setting about the controller and use a text_field :tableelement that work, but with your f.text_field 'fromemail' i got this error. Thanks for your help – neimad Sep 03 '11 at 18:29