Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:35:23+00:00 2026-05-30T08:35:23+00:00

I have a basic application with a user model. When the user creates an

  • 0

I have a basic application with a user model. When the user creates an account I would like to sent them an email. I originally had this setup in the controller itself.

if @user.save
  UserMailer.welcome_email(@user, new_session_url).deliver
  redirect_to root_url, notice: 'User was successfully created.  Please check your email for more information'

This seemed fine to me at the time. I later learned about Observers in Rails. A common example of using an observer was to move this email logic above outside of the controller and into a “user observer”. This seemed like a great idea.

I immediately ran into 2 major problems:

  1. My observer cannot access new_session_url. I really want to be able to include in my email to the user a link back to the login page. I am shocked to see so many examples of using an observer for this, without touching on this issue.
  2. My observer has no access to flash messages. It can’t notify the user that an email was sent.

My question is this. Should I be trying to use an observer here. Its starting to look like I would have a much easier time using callbacks for this directly in the controller. If this is not an appropriate use case for an observer than what is? This situation seems to be one of the primary examples of using an observer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:35:25+00:00Added an answer on May 30, 2026 at 8:35 am

    You dont have to access the session-url(even flash) in the observer.

    You just have to call the method like this:

    Controller

    if @user.save
      redirect_to root_url, notice: 'User was successfully created.  Please check your email for more information'
    end
    

    Observer:

    def after_create(user)
      UserMailer.welcome_email(user).deliver
    end
    

    You have to use the session-url in the actual view:

    welcome_email.html.erb

    <%= new_session_url %>
    

    In this way we can test the email logic separately. Also if there are multiple entry points for creating an user, you dont have to replicate the logic everywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a django application, using the basic userprofile extension of django.contrib.auth.user model. I
I have a basic quiz/survey type application I'm working on, and I'd like to
In my application I have some basic user information that needs to be displayed
I have a pretty basic Paperclip Upload model that is attached to a User
I have a user entity in my application where users input some basic information
I have 2 basic models in my CakePHP application: User and Login. A user
I have a Visual Basic 6.0 application that needs to recognise when the user
I have a basic ajax application, which will not work, instead the php code
I have written a basic Application for windows mobile 5. It is using visual
Guys, I have a basic WPF application. Contains App.xaml as always and a Mainwindow.xaml.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.