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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:02:06+00:00 2026-06-01T17:02:06+00:00

I am creating a basic app for an address book and would like to

  • 0

I am creating a basic app for an address book and would like to associate Contacts with Users.

I have set up authentication for Users and am now in the process of trying to link my contacts table with the users. I have two seperate controllers, one for users and another for contacts and then my plan is to associate them through belongs_to:user and has_many :contacts.

I am absolutely stumped by an error I keep receiving though

undefined method `new' for Contact:Module

As far as I am aware I have defined new correctly in my contact controller but for some reason I can’t get this to work.

I have the following code at the moment

Routes:

Contact::Application.routes.draw do

get "sessions/new"
get "logout" => "sessions#destroy"

controller :user do
get "signup" => "user#new"
end

resources :users, :controller => 'user'

controller :sessions do
get "login" => "sessions#new"
post "login" => "sessions#create"
delete "logout" => "sessions#destroy" 
end

controller :dashboard do
get "home" => "dashboard#home"
end

controller :contact do
get "newcontact" => "contact#new"
end

resources :contacts, :controller => 'contact'

root :to => 'sessions#new'


end

Contact Controller

class ContactController < ApplicationController
def new
@contact = Contact.new
end

def create
@contact = Contact.new (params[:contact])
  if @contact.save
    redirect_to root_url
  else
    render "contact#new"
end
end
end

Contact/new Form

<%= form_for @contact do |f| %>

<% if @contact.errors.any? %>
    <div class="error_messages">
     <h2>Form is invalid</h2>
        <ul>
            <% for message in @contact.errors.full_messages %>
                <li><%= message %></li>
            <% end %>
        </ul>
    </div>
<% end %>   
<div class = "name-field">
    <%= f.text_field :name, :placeholder => "Name" %>
</div>

<div class = "company-field">
    <%= f.text_field :company, :placeholder => "Company" %>
</div>

<div class = "email-field">
    <%= f.text_field :email, :placeholder => "Email" %>
</div>

<div class = "phone-field">
    <%= f.text_field :phone, :placeholder => "Phone" %>
</div>

<div class = "mobile-field">
    <%= f.text_field :mobile, :placeholder => "Mobile" %>
</div>  

<div class="actions"><%= f.submit "Add Contact" %></div>
</div>
<% end %>

Any help people can offer to fix this error really would be much appreciated because I am totally stuck! I think it might be something to do with pluralisation of the word contact but can’t seem to find the correct way to fix it.

Many thanks in advance for your help!
Tom

  • 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-01T17:02:08+00:00Added an answer on June 1, 2026 at 5:02 pm

    Rails is getting confused between the module defined in application.rb (Contact) and your model class (also Contact). You can’t have module Contact in one place and class Contact in another (in fact since you’re in development mode, the fact that the Contact module exists means that rails isn’t even looking at your contact.rb file)

    You’re going to have to rename one of them. The application one might be the easier one to change – just replace all instances of Contact::Application with (eg) ContactApp::Application and change module Contact in application.rb to module ContactApp. You also barely ever type the name of the application module so it having a slightly dissonant name isn’t too much of a big deal.

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

Sidebar

Related Questions

I have an ASP.NET app, very basic, but right now too much code to
I'm new to visual basic and have been tasked with creating an app that
What should I read for creating a basic augmented reality app for android? I
My current class is planning on creating a basic networked game, but we have
I am working on my first ever android app, and I'm creating basic exercise/calorie
I am creating a very basic App for the iPhone & iPad and it's
Im creating a very basic Android App. All it does is renders a mobile
I'm following a very basic book tutorial on Mac development. We're just creating a
I'm creating a basic blog app with rails/mongoid backend and an iOS client that
I have been busy creating an app for Red5. Imagine what was my surprise

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.