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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:27:38+00:00 2026-06-10T23:27:38+00:00

First SO post, but I’ve read so many. I’m new to Rails and building

  • 0

First SO post, but I’ve read so many. I’m new to Rails and building first site since studying Hartl’s RailsTutorial.

My issue is routing using STI. I believe the routes are set up correctly, but the subclass Kid doesn’t find a “show” route.

Class inheritance using STI

class User < ActiveRecord::Base

class Kid < User

Kid Controller

def show

@kid = Kid.find(params[:id])

end

User Controller create

def create
@user = User.new(params[:user])
if @user.save
  flash[:success] = "Welcome to kidtunes!"
  if (@user.type = "Kid")
    ***redirect_to @kid***
  else
redirect_to @parent
  end
else
  render 'new'
end

routes.rb

resources :users, :kids, :parents

root to: ‘static_pages#home’

match ‘/help’, to: ‘static_pages#help’

match ‘/contact’, to: ‘static_pages#contact’

match ‘/signup’, to: ‘users#new’

Results in:

kids_new    GET    /kids/new(.:format)         kids#new
  users     GET    /users(.:format)            users#index
            POST   /users(.:format)            users#create
   new_user GET    /users/new(.:format)        users#new
  edit_user GET    /users/:id/edit(.:format)   users#edit
   user     GET    /users/:id(.:format)        users#show
            PUT    /users/:id(.:format)        users#update
            DELETE /users/:id(.:format)        users#destroy
   kids     GET    /kids(.:format)             kids#index
            POST   /kids(.:format)             kids#create
new_kid     GET    /kids/new(.:format)         kids#new
   edit_kid GET    /kids/:id/edit(.:format)    kids#edit
    kid     GET    /kids/:id(.:format)         kids#show
            PUT    /kids/:id(.:format)         kids#update
            DELETE /kids/:id(.:format)         kids#destroy
parents     GET    /parents(.:format)          parents#index
            POST   /parents(.:format)          parents#create
 new_parent GET    /parents/new(.:format)      parents#new
edit_parent GET    /parents/:id/edit(.:format) parents#edit
 parent     GET    /parents/:id(.:format)      parents#show
            PUT    /parents/:id(.:format)      parents#update
            DELETE /parents/:id(.:format)      parents#destroy
   root            /                           static_pages#home
   help            /help(.:format)             static_pages#help
contact            /contact(.:format)          static_pages#contact
 signup            /signup(.:format)           users#new

Error
I get the following on redirect_to @kid

ActionController::ActionControllerError (Cannot redirect to nil!):
app/controllers/users_controller.rb:16:in `create’

I feel like I’ve checked everything I can check, but I’m still missing something. @kid should properly redirect to the kids#show route. I’m not sure if I have a poorly crafted single table inheritance or a basic routing issue.

thanks in advance.
-John

Form

This form is used in users/new.html.erb and it creates the User.

<div class="row">
<div class="span5 offset2">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :fname, "First Name" %>
<%= f.text_field :fname %>

<%= f.label :lname, "Last Name" %>
<%= f.text_field :lname %>

<%= f.label :email %>
<%= f.text_field :email %>

<%= f.label :type, "Are you a Kid or Parent?" %>
<%= f.select :type, [['Kid','Kid'],['Parent','Parent']] %>

<%= f.label :password %>
<%= f.password_field :password %>

<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>

<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>

  • 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-06-10T23:27:40+00:00Added an answer on June 10, 2026 at 11:27 pm

    Have you defined/assigned values to the @kid or @parent variables? If not, they will be nil, and you’ll get the cannot redirect to nil error you’ve included in your question.

    Please include the full code for the create action. Otherwise we’re left to trust (rather than read for ourselves) precisely what’s happening in the redirect.

    Your redirects might also need some work. For example, you could do:

    if (@user.is_a? Kid)
      redirect_to kid_path(@user)
    else
      redirect_to parent_path(@user)
    end
    

    …or something very similar to that.

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

Sidebar

Related Questions

I'm pretty new to rails and this is also my first post, but I'm
This is my first post, I'm new to this site, but I've been lurking
This is my first post here, but I'm not new to the site (call
This is my first post, but I've loved using this site as resource for
This is my first post, but I have been using this site for a
This is my first post, but I've been using the site for years. However,
this is my first post to stackoverflow, but I've used this amazing site before.
my first post here. I'm not new to JQuery, but I find complex coding
Hi guys first post on this site so excuse the formatting. I'm new to
This is my first post here, but I've using this site regularly to help

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.