Skip to content

Instantly share code, notes, and snippets.

@rafaelrpbelo
Last active December 19, 2015 10:58
Show Gist options
  • Save rafaelrpbelo/5943870 to your computer and use it in GitHub Desktop.
Save rafaelrpbelo/5943870 to your computer and use it in GitHub Desktop.
undefined method `send_mailer' for ContactMailer:Module Extracted source (around line #10): if @user_mailer.valid? ContactMailer.send_mailer(@user_mailer).deliver redirect_to :root, :notice => "Successfully sent!" else Rails.root: /home/rafael/rafaelbelo/contact_mailer app/controllers/contacts_controller.rb:10:in `mail_contact'
class ContactMailer < ActionMailer::Base
default from: "no-reply@test.com"
def send_mailer(user_mailer)
@user_mailer = user_mailer
mail(to: "rafaelrpb@hotmail.com",
subject: "New Email",
body: "Test Its Works.."
)
end
end
class ContactsController < ApplicationController
def index
@user_mailer = UserMailer.new
end
def mail_contact
@user_mailer = UserMailer.new(params[:user_mailer])
if @user_mailer.valid?
ContactMailer.send_mailer(@user_mailer).deliver
redirect_to :root,
:notice => "Successfully sent!"
else
render :action => "index", :notice => "Error in the sent!"
end
end
end
undefined method `send_mailer' for ContactMailer:Module
Extracted source (around line #10):
if @user_mailer.valid?
ContactMailer.send_mailer(@user_mailer).deliver
redirect_to :root,
:notice => "Successfully sent!"
else
Rails.root: /home/rafael/rafaelbelo/contact_mailer
app/controllers/contacts_controller.rb:10:in `mail_contact'
<h1>Contact</h1>
<%= notice %>
<%= form_for :user_mailer, url: { action: "mail_contact" } do |f| %>
<p>
<%= f.label :name, "Name:" %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :email, "Email:" %><br />
<%= f.text_field :email %>
</p>
<p>
<%= f.label :company, "Company:" %><br />
<%= f.text_field :company %>
</p>
<p>
<%= f.submit("Send") %>
</p>
<% end %>
class UserMailer
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :email, :company
validates_presence_of :name, :email, :company
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
@boddhisattva
Copy link

Shouldn't line 7 in contacts_controller.rb be :- @user_mailer = UserMailer.find(params[:user_mailer]) instead of @user_mailer = UserMailer.new(params[:user_mailer]) ?

Have you defined "valid?" as an action, somewhere in your code or is it a built in Rails method synonymous to present? ?

@esendjaja
Copy link

ActionMailer 2 or 3?

with ActionMailer 2, you need to write: ContactMailer.deliver_send_mailer(@user_mailer)
Do you really need @user_mailer as argument?

@tommeier
Copy link

tommeier commented Jul 8, 2013

You're trying to send_mail as a class method but it is actually an instance method.

Like UserMailer, you should be doing

something = ContactMailer.new(params[:x])

something.send_mailer(user).deliver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment