4

I'm working on building out my mailer, but I keep running into:

wrong number of arguments (0 for 1)

Call my crazy, but I feel like I defined everything correctly:

Controller (truncated for brevity):

def create
@cms484 = Cms484.new(cms484_params)

respond_to do |format|
  if @cms484.save
    SendLink.message(@cms484).deliver_later
    format.html { redirect_to cms484s_path, notice: 'Cms484 was successfully created.' }
    format.json { render :show, status: :created, location: @cms484 }
  else
    format.html { render :new }
    format.json { render json: @cms484.errors, status: :unprocessable_entity }
  end
end

SendLink.rb:

    class SendLink < ApplicationMailer
    def message(cms484)
    @cms484 = cms484
    mail(
      :subject => 'Hello from Postmark',
      :to  => @cms484.recipient ,
      :from => 'info@mysite.com',
      :html_body => '<strong>Hello</strong> user!.',
  end
end

Can anybody else see the needle in the haystack or am I missing something else entirely?

I'm using Postmark for delivery if that matters, and have those parameters defined in my application.rb file as per the documentation. Think this is a simpler matter though.

Edit The complete error:

Completed 500 Internal Server Error in 76ms

ArgumentError (wrong number of arguments (0 for 1)):
  app/mailers/send_link.rb:2:in `message'
  app/mailers/send_link.rb:4:in `message'
  app/controllers/cms484s_controller.rb:38:in `block in create'
  app/controllers/cms484s_controller.rb:36:in `create'
PSCampbell
  • 834
  • 9
  • 22

3 Answers3

5

I had a similar issue where I named my ActionMailer method "message" it turns out it was a reserved word in Rails and threw an error.

I would assume that "mail" was a reserved word where "email" was not.

Brandon Smith
  • 53
  • 1
  • 4
0

mail ... line in SendLink.rb looks wrong , change it to,

 mail(
  :subject => 'Hello from Postmark',
  :to  => @cms484.recipient ,
  :from => 'info@mysite.com',
  :html_body => '<strong>Hello</strong> user!.')
jon snow
  • 2,992
  • 1
  • 16
  • 30
  • I'm not seeing any difference in what I posted and your suggestion? Copied and pasted suggestion just to be sure and still seeing same 0 for 1 error. – PSCampbell Jun 05 '15 at 01:12
  • Its a syntax problem, checkout `, and ) ` . But i think this isn't solved your problem as mentioned in question's comments. So keep going. – jon snow Jun 05 '15 at 04:27
0

Ok, so I decided to re-write it and behold - it works. Why or what's different than the previous version(other than the method email vs mail, surely that can't be it?), I have no idea. If you can see what it is, Please point it out to me!

Send_link.rb:

class SendLink < ApplicationMailer



def email(cms484)
    @cms484 = cms484
     mail(
  :subject => 'Hello from Postmark',
  :to  => @cms484.recipient ,
  :from => 'info@mysite.com',
)
  end
end

Controller:

def create
@cms484 = Cms484.new(cms484_params)

respond_to do |format|
  if @cms484.save
    SendLink.email(@cms484).deliver_later

    format.html { redirect_to cms484s_path, notice: 'Cms484 was successfully created.' }
    format.json { render :show, status: :created, location: @cms484 }
  else
    format.html { render :new }
    format.json { render json: @cms484.errors, status: :unprocessable_entity }
  end
end 

end

PSCampbell
  • 834
  • 9
  • 22