Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ group :development do
gem 'spring'
gem 'guard'
gem 'guard-livereload', require: false
gem "letter_opener"
#gem para ver los correos que se envían cuando estoy local
#requiere una configuración local en environtment
end

# Use ActiveModel has_secure_password
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.1)
tzinfo (~> 1.1)
addressable (2.3.6)
arel (5.0.1.20140414130214)
bcrypt (3.1.7)
builder (3.2.2)
Expand Down Expand Up @@ -79,6 +80,10 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.3.0)
launchy (~> 2.2)
listen (2.7.11)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
Expand Down Expand Up @@ -166,6 +171,7 @@ DEPENDENCIES
guard-livereload
jbuilder (~> 2.0)
jquery-rails
letter_opener
pry
rails (= 4.1.6)
sass-rails (~> 4.0.3)
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/friends_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class FriendsController < ApplicationController
before_action :authenticate_user!


def index
@friend = current_user.random_friend
# render :index (default behavior)
Expand All @@ -15,7 +16,12 @@ def like
current_user.likes.create(friend_id: @friend.id, liked: like_or_unlike)

if @friend.liked?(current_user)
FriendMailer.email_friend(@friend, current_user).deliver
FriendMailer.email_current_user(@current_user , @friend).deliver

render :match


else
redirect_to root_path
end
Expand Down
19 changes: 19 additions & 0 deletions app/mailers/friend_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class FriendMailer < ActionMailer::Base
default from: "[email protected]"


def email_friend(friend, current_user)
@user_liked = friend
@user_who_likes = current_user
mail(to: @user_liked.email, subject: 'Alguien quiere conocerte')
end

def email_current_user(current_user, friend)
@user_who_likes = current_user
@user_liked = friend
mail(to: @user_who_likes.email, subject: 'Le has dado te gusta a un amigo')
end

end


11 changes: 11 additions & 0 deletions app/views/friend_mailer/email_current_user.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1> hola <%= @user_who_likes %></h1>
    <p>Le has dado like a <%= @user_liked.name %> </p>

  </body>
</html>
10 changes: 10 additions & 0 deletions app/views/friend_mailer/email_friend.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Alguien te quiere conocer, <%= @user_liked.name %></h1>
    <p>glkdfglfjgld</p>
  </body>
</html>
10 changes: 9 additions & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true }
end