Virge Assault Virge Assault - 3 months ago 32
Ruby Question

ActionView::Template::Error (undefined method `phone' for #<User:0x007f35612a5448>):

I finished creating user sign-up for my new rails app and everything worked fine in development on my local machine. But on heroku the deployed app will show the homepage and most other pages except the signup_path which renders "new.html.erb". Clicking this path gives me an error telling me to check my logs.

I've checked the logs and have tried several things but don't know what to do now. Here are the logs:

Here's the home page which works fine, but the path attached to "sign in" doesn't


<% provide(:title, "Home") %>

<div class="center jumbotron">
<h1>sample app</h1>

<%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>


Rails.application.routes.draw do

get 'users/new'

root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
resources :users

And my sign up page that is supposed to load:


<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>

<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>

<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>

<%= f.label :phone, "Phone Number" %>
<%= f.phone_field :phone, class: 'form-control' %>

<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>

<%= f.label :password_confirmation, "Confirm Your Password" %>
<%= f.password_field :password_confirmation, class: 'form-control' %>

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


<!DOCTYPE html>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>


class User < ActiveRecord::Base
before_save { = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
VALID_PHONE_REGEX = /\A(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}\z/
validates :phone, presence: true, length: {maximum: 15},
format: { with: VALID_PHONE_REGEX },
uniqueness: true
validates :password, length: { minimum: 6 }

My production schema, where I believe phone is defined:

ActiveRecord::Schema.define(version: 20150204094519) do

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.string "phone"

add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["phone"], name: "index_users_on_phone", unique: true


Heroku Migrations:

20150204074511_create_users.rb 20150204093042_add_phone_number_to_users.rb
20150204081616_add_index_to_users_email.rb 20150204094519_add_index_to_users_phone_number.rb

Happy to add any other files if necessary. I'm running the final gemfile from Hartl's newest tutorial. Don't know what else to do.


Their is no such phone_field in rails, change it to text_field or number_field or telephone_field.

<%= f.phone_field :phone, class: 'form-control' %>


<%= f.text_field :phone, class: 'form-control' %>


<%= f.telephone_field :phone, class: 'form-control' %>