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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:45:45+00:00 2026-05-20T04:45:45+00:00

I have a couple of simple models that are associated like so: MODELS class

  • 0

I have a couple of simple models that are associated like so:

MODELS

class Task < ActiveRecord::Base
  belongs_to :user
  validates :name, :presence => true, :message => 'Name cannot be blank, Task not saved'
end

class User < ActiveRecord::Base
  has_many :tasks
end

VIEW has a call in it like so:
user.tasks <– then I loop through the tasks

The Issue:

In the task model —

when I use:

validates :name, :presence => true ,  :message => 'Name cannot be blank, Task not saved'

I get a 500 error:

ActionView::Template::Error (uninitialized constant User::Task):
NameError in View file

when I use:

validates_presence_of :name

Everything works.

I thought the both validates methods above where the same…is the issue have to do with associations and how validation tie into associated models. I have a hunch that something is going on with the way things are associated, but it is just a hunch.

Any help will be appreciated. Thank very much.

  • 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-20T04:45:46+00:00Added an answer on May 20, 2026 at 4:45 am

    When you use the newer validates :name format, you can put multiple validations in one line rather than having to have multiple lines for each type of validation. Because of this, when Rails hits your :message parameter, it thinks it’s a validation method rather than a message associated with :presence. Try this instead:

    validates :name, :presence => {:message => 'Name cannot be blank, Task not saved'}
    

    Also, depending on how you display your errors, this error may actually show up as ‘Name Name cannot be….’; if so, you’ll want to set the message to just ‘cannot be blank, Task not saved’.

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

Sidebar

Related Questions

I have a couple of simple forms that send an html-only email. Most clients
I recently made this simple navigation where you have a couple links that have
I have a couple of simple objects that have a many-to-many relationship. Django has
Given a very simple object: class User { private Integer id; private String name;
I have a simply Class that is intended to be a simple POCO -
I have made a simple web-page including a couple of static pages, a css
I have couple of dozen pieces of data that I need to save and
I have couple resource DLLs that I currently load when application starts using following
I have a GUI which has a couple of checkboxes that control special modes
I have what I thought was a fairly simple many to many association that

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.