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

  • Home
  • SEARCH
  • 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 8613319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:50:53+00:00 2026-06-12T04:50:53+00:00

***SOLVED Oops! I forgot to migrate plan_id over to the users table… After Michael

  • 0

***SOLVED Oops! I forgot to migrate plan_id over to the users table…

After Michael Hartl’s tutorial, I’ve been bugging away at an app of my own. Right Now, there are two tables — Plans, and Users. The plan has_many users, and the users belong_to Plans, and now what I’m trying to do is finish the registration process, so when someone goes to the signup form via a plan_id=?, it submits it to a hidden form field, and registers the user.

However, when I try to visit my signup_path, I get this error :

ActiveRecord::UnknownAttributeError in UsersController#new

unknown attribute: plan_id

I’m not quite sure what to make of it. Would love your thoughts!

Users Controller

class UsersController < ApplicationController

  before_filter :signed_in_user, only: [:show]
  before_filter :correct_user,   only: [:show]

    def show
    @user = User.find(params[:id])
    end

    def new
  plan = Plan.find(params[:plan_id])
    @user = plan.users.build
    end

  def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      render 'new'
    end
  end

  def index

    if current_user
      redirect_to(user_path(current_user))
    else
    redirect_to(root_path)
    end
  end

  private

    def signed_in_user
      unless signed_in?
        store_location
        redirect_to login_url, notice: "Please sign in."
      end
    end

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_path) unless current_user?(@user)
    end
end

Views/users/new.html.erb

<% provide(:title, 'Sign up') %>
<div class="contentstripe">
<div class="container">
  <div class="row">
   <h1>Sign Up </h1>
  </div>
</div>
</div>

<div class="container">
 <div class="row">
  <div class="span6 offset3">
    <%= form_for(@user) do |f| %>

      <%= f.hidden_field :plan_id %>

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

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

      <%= 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 %>
  </div>
</div>
</div>

Plan Model

# == Schema Information
#
# Table name: plans
#
#  id                :integer          not null, primary key
#  name              :string(255)
#  max_phone_numbers :integer
#  max_minutes       :integer
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  price             :decimal(, )
#

class Plan < ActiveRecord::Base
  has_many :users
end

User Model

# Twilio authentication credentials
TWILIO_PARENT_ACCOUNT_SID = '##redacted' ##Development
TWILIO_PARENT_ACCOUNT_TOKEN = '##redacted'

# == Schema Information
#
# Table name: users
#
#  id                 :integer          not null, primary key
#  name               :string(255)
#  email              :string(255)
#  created_at         :datetime         not null
#  updated_at         :datetime         not null
#  password_digest    :string(255)
#  remember_token     :string(255)
#  twilio_account_sid :string(255)
#  twilio_auth_token  :string(255)
#

class User < ActiveRecord::Base
  belongs_to :plan
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password

  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token
  before_save :create_twilio_subaccount

  validates :name,  presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
                    uniqueness: true

  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true
  validates_presence_of :plan_id

  private

      def create_remember_token
        self.remember_token = SecureRandom.urlsafe_base64
      end

    def create_twilio_subaccount     
      @client = Twilio::REST::Client.new(TWILIO_PARENT_ACCOUNT_SID, TWILIO_PARENT_ACCOUNT_TOKEN)
      @subaccount = @client.accounts.create({:FriendlyName => self[:email]})
      self.twilio_account_sid = @subaccount.sid
      self.twilio_auth_token  = @subaccount.auth_token
    end

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-12T04:50:54+00:00Added an answer on June 12, 2026 at 4:50 am

    The url to your UsersController#new method must contain a plan_id part followed by a id which is supposed to be received by params[:plan_id]. Is your url like that? Can you add your related part of the output of rake routes.

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

Sidebar

Related Questions

SOLVED: Crap... why is it always you figure something out right AFTER you finally
@Solved The two subquestions I have created have been solved (yay for splitting this
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView
SOLVED: Thanks to @SJFrK, my issue has been solved. The following class allows me
Solved: i just managed to solve the problem by creating a new table and
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
Solved - Problem with constructor Matthew Flaschen and Michael Burr pointed out the problem
SOLVED: Datatypes in the table for country and OS were set to VARCHAR so
[SOLVED] I am following this tutorial link I have a buttons in my Main
Solved Hi currently im using SimpleXLSX to parse the xlsx (excel file), all the

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.