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 5993033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:37:01+00:00 2026-05-22T23:37:01+00:00

this is my first question here and I am currently trying to build my

  • 0

this is my first question here and I am currently trying to build my first Ruby on Rails app so this question might be kind of basic.

The Problem:

I want a form on the root site which consists of only two fields, email and password for a user model. Depending on whether the email address that was typed in already exists or not, the form should forward the request to the ‘users#create’ (i.e. create a new user) or the ‘sessions#create’ (i.e. Sign the user in … if the password is correct)

What I tried:

To solve this I created a new action in the pages controller called ‘decide’ and pointed the form to that page.

It basically looks like this:

def decide
  if User.find_by_email(params[:email])
    # Copied in all of the code from sessions#create
    # with a redirect at the end so a /decide page doesn't get rendered
  else
    # Copied in all of the code from users#create
    # with a redirect at the end so a /decide page doesn't get rendered
  end
end

—

Now this works and I’m pretty proud of myself that I figured it out as a complete beginner, but I can hear experienced programmers crying out in agony at this code. I’m pretty sure this is not the “Rails Way”.

I repeat a large amount of code and I feel like I’m putting something in a controller that wasn’t made for that purpose.

Another problem is that I can’t get my rspec integration test to work, which basically goes to the root_path, fills in the form with a new user, hits the button and expects a success flash… but the test gets returned an empty html document on pressing the button. Although it works perfectly fine when I do the same thing in a browser.

So I figured:

Couldn’t you somehow put the above if statement in the routes.rb file and redirect the request to the respective controller and action?

If so how?

Or does anyone have a different idea how to accomplish this?

Thank you,

-Konstantin

  • 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-22T23:37:03+00:00Added an answer on May 22, 2026 at 11:37 pm

    Actually, that’s a fairly solid way of handling the problem.

    Routes in Rails are only supposed to be a simple way of mapping URLs to code. Logic like that belongs exactly where you’ve placed it: in the controller.

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

Sidebar

Related Questions

This is my first here in Stackoverflow. So I just want to ask question
I am currently trying to build the distribution product of my (first) iphone app
this is my first question here :) I know that I should not check
This is my first question here so try to make my best so you
Ok, I need help. This is my first question here. Background: I am working
this is my first question.. so, here we go. i have a site, 100%
Sorry, this's my first time to ask a question here. So, I don't have
Here's my HTML. Apologies for formatting - this is my first-ever question! <div id=Template>
This is my first time here so I hope I post this question at
this is my first time posting here, I have a question which I have

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.