logo
down
shadow

How to pass user attributes to action mailer


How to pass user attributes to action mailer

By : user2956728
Date : November 22 2020, 03:03 PM
I wish this help you You are not passing @comment object to CommentsMailer and trying to access it there.
Instead of passing User object (@user) to CommentsMailer in create action CommentsMailer.new_comment(@user).deliver. Try pass @comment object.
code :
def create
  @comment = Comment.new comment_params

  if @comment.valid?
    CommentsMailer.new_comment(@comment).deliver
    flash[:success] = "We have receieved your message!"
    redirect_to users_path
  else
    flash.now.alert = "Please fill in all fields."
    render :new
  end
end
class CommentsMailer < ActionMailer::Base
  default to:   "myemail@gmail.com"
  default from: "@comment.user.email"

  def new_comment(comment)
    @comment = comment
    @user = @comment.user
    mail(subject: '@comment.subject')
  end

end


Share : facebook icon twitter icon
Send email to other user not logged in with action mailer for rails

Send email to other user not logged in with action mailer for rails


By : Milind
Date : March 29 2020, 07:55 AM
To fix this issue To answer your question based on the create action you are not creating the @user2 instance for that action. An instance variable does not carry from the new => create action, or edit => update. So all you need to add is
code :
@user2 = User2.find(params[:user2_id]) #assuming you have the user2_id as part of the submitted form.
@user2 = @user.user2 #this will return an array of associated user_2's
def create

   @message = current_user.messages.build(params[:message])
   @user2 = User2.find(params[:user2_id]) #or whatever selector

   respond_to do |format|
   if @message.save

   UserMailer.new_message_sent_user(current_user).deliver
   ...
end
Send User email after creating a post, with Action Mailer

Send User email after creating a post, with Action Mailer


By : Marián Bednárik
Date : March 29 2020, 07:55 AM
this one helps. Create another mailer (http://railscasts.com/episodes/206-action-mailer-in-rails-3)
code :
 class YourMailerName < ActionMailer::Base
     default :from => "you@example.com"

   def post_email(user)
    mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
   end
 end
 after_create :send_email

 def send_email
   YourMailerName.post_email(self.user).deliver
 end
Using Action Mailer and ROR3 to send an email on the creation of user

Using Action Mailer and ROR3 to send an email on the creation of user


By : Votar
Date : March 29 2020, 07:55 AM
it fixes the issue You're mixing your capitalization up a little. You should use UserMailer (with a capital 'M') to refer to the constant (a.k.a. class) and user_mailer for the file and directory names.
So for your mailer, the file name should be app/mailers/user_mailer.rb and then use:
code :
class UserMailer < ActionMailer::Base
# First, going from the constant to the file name to look for:
UserMailer.name.underscore  # => 'user_mailer'

# Now, going from the file name to the expected constant defined in that file:
'user_mailer`.classify  # => 'UserMailer'
'UserMailer'.constantize  # => UserMailer
Where to put controller UserMailer.signup_confirmation(@user).deliver from Railscast on Action Mailer

Where to put controller UserMailer.signup_confirmation(@user).deliver from Railscast on Action Mailer


By : Black Star
Date : March 29 2020, 07:55 AM
With these it helps Without Devise
Since, you are following the RailsCasts episode for Sending Email then in that case all you need to do is update UsersController#create as below:
code :
def create
  @user = User.new(params[:user])
  if @user.save
    UserMailer.signup_confirmation(@user).deliver  ## Add this
    redirect_to @user, notice: "Signed up successfully."
  else
    render :new
  end
end
class ApplicationController < ActionController::Base
  ## ...
  protected

  def after_sign_in_path_for(resource)
    UserMailer.signup_confirmation(@user).deliver  ## Add this
    your_path(resource)  ## Replace your_path with the path name where you want to send the user after sign in 
  end
end 
Pass multiple objects into action mailer/email contents in rails

Pass multiple objects into action mailer/email contents in rails


By : user2975349
Date : March 29 2020, 07:55 AM
Does that help This is a classic case of your debug code giving you the wrong impression. Your @post is getting passed in fine - but it's happening after the call to binding.pry.
You pass in your post to announcement_alert, which sets it as an instance variable. If you updated that method to look like this, you should see it set fine:
code :
def announcement_alert(announcement, post)
  @announcement = announcement
  @post = post
  binding.pry    
  mail(subject: "#{@post.slug}: #{@announcement.title}")
end
default to: Proc.new { Signup.where(post_id: @post.id, user_id: current_user.id).pluck(:email) }, 
        from: "#{@post.slug}@fundspace.announcement.com"
default to: Proc.new { Signup.where(post_id: @post.id, user_id: current_user.id).pluck(:email) }, 
        from: Proc.new { "#{@post.slug}@fundspace.announcement.com" }
Related Posts Related Posts :
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • One action in Rails controller sends no data back
  • Local data (JSON) in Middleman inside a different path than /data
  • How to pass numbers in an array into a SQL statement
  • ActiveAdmin - Allow non-logged-in users to view but not edit resources
  • How to refactor this Model logic in Rails
  • :readonly key of belongs_to method doesn't work
  • Create a new view in directory
  • nested resources in devise
  • Yaml value with a leading `!`
  • Rails admin show username instead of User #5
  • Can't start WEBrick with Byebug on
  • Failing Rspec test of a FactoryGirl object
  • engine yard No application found matching remotes:
  • Rails 4 sessions cookie is not set
  • How do I flush a class method in Rails 4 using memcached?
  • AJAX form submitting in HTML rails 4
  • Using greater than or less than in a Rails Active Record query
  • Searching Post by Origin & Destination locations using Geokit-Rails
  • Deploying application to two different servers, with different production.rb contents
  • Spree with deface - Use deface to replace contents of block
  • I need to change date part of DateTime variable
  • Ruby on Rails 4 - Using Rake on Heroku
  • Ruby symbol setup
  • rescue inside an each_line code block
  • RoR/Squeel - How do I use Squeel::Nodes::Join/Predicates?
  • Using a different key name for an association attribute in rails api active model serializer
  • Running callbacks in rspec
  • Ruby on rails: wrong number of arguments (Devise and parsley-rails gems)
  • Query with Date.today returns two days
  • select all the values of the records belonging to a specific field of the database and save them in a array Active Recor
  • RSPEC test index action with before_action filter
  • Rails model columns and performance
  • keys and values from an ajax POST are all escaped
  • What is the formula for setting WEB_CONCURRENCY on heroku?
  • How to select objects based on their enum value and then sum another field belonging to the object collection in Rails
  • Why are there frozen constants everywhere?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org