Last active
December 26, 2015 12:07
-
-
Save felipecabargas/7e6e0fa5f634531cf636 to your computer and use it in GitHub Desktop.
Mailer Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/application.rb | |
module RailsApp | |
class Application < Rails::Application | |
config.action_mailer.smtp_settings = { | |
:address => "smtp.live.com", | |
:port => 587, | |
:domain => "squape.com", | |
:user_name => "[email protected]", | |
:password => "squapeco", | |
:authentication => :plain, | |
:enable_starttls_auto => true | |
} | |
config.action_mailer.default_url_options = { | |
:host => "squape.com" | |
} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/controllers/contact_controller.rb | |
class ContactController < ApplicationController | |
def new | |
@message = Message.new | |
end | |
def create | |
@message = Message.new(params[:message]) | |
if @message.valid? | |
NotificationsMailer.new_message(@message).deliver | |
redirect_to(root_path, :notice => "El mensaje fue enviado correctamente. Te contactaremos a la brevedad (:") | |
else | |
redirect_to(contact_path, :notice => "Hay campos incompletos, intenta nuevamente.") | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/views/contact/new.html.haml | |
=render('layouts/header') | |
- if flash[:notice] | |
.row | |
.alert-message.warning.large-8.columns.large-centered | |
%p | |
= flash[:notice] | |
.content | |
.row | |
.large-6.columns#mision | |
%h3 Contacto | |
.row | |
= form_for @message, :url => contact_path do |form| | |
%fieldset.fields | |
.field | |
= form.label :nombre | |
= form.text_field :name | |
.field | |
= form.label :email | |
= form.text_field :email | |
.field | |
= form.label :asunto | |
= form.text_field :subject | |
.field | |
= form.label :cuerpo | |
= form.text_area :body | |
%fieldset.actions | |
= form.submit "Enviar" | |
=render('layouts/footer') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/notifications_mailer/new_message.text.erb --> | |
Name: <%= @message.name %> | |
Email: <%= @message.email %> | |
Subject: <%= @message.subject %> | |
Body: <%= @message.body %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/controllers/notifications_mailer.rb | |
class NotificationsMailer < ActionMailer::Base | |
default :from => "[email protected]" | |
default :to => "[email protected]" | |
def new_message(message) | |
@message = message | |
mail(:subject => "[SQUAPE.com] #{message.subject}") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/routes.rb | |
match 'contact' => 'contact#new', :as => 'contact', :via => :get | |
match 'contact' => 'contact#create', :as => 'contact', :via => :post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment