dimanche 10 mai 2015

Rails :Action mailer Send mails to multiple users based on their tags

I wanted to send mails to users based on their tags assigned to the user,I have implemented a simple mail sending when user creates a post till now.But how filter tags based on user before sending mail.

class PostMailer < ActionMailer::Base
        def post_created(user,current_user,post,location)

                @current_user = current_user.email
                @post = post
                @user = user.email
                @location = location

                mail(
                        to: user.email,
                        from:"services@yourdomain.com",
                        subject:"You have a new Post",
                )
        end
end
class PostsController < ApplicationController
        before_action :find_post, only: [:show, :edit, :update, :destroy]
        before_action :authenticate_user!,except:[:index]

    def create

                @post = current_user.posts.build(post_params)
                @post.user_id = current_user.id if current_user
                @user = current_user
                if      @post.save
                        PostMailer.post_created(@user,@current_user,@post.post,@post.location).deliver
                end
                if @post.save
                        redirect_to @post
                else
                        render 'new'
                end

        end

Aucun commentaire:

Enregistrer un commentaire