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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:53:52+00:00 2026-05-31T12:53:52+00:00

Using Rails 3.1.3. I have Accounts and Users. One Account can have many Users.

  • 0

Using Rails 3.1.3. I have Accounts and Users. One Account can have many Users. I set this up using accepts_nested_attributes_for as described in this answer.

I have a new.html.erb view that accepts data for one account and one user at the same time. (The user’s data goes into a “subform.”) The form works fine. However if there is an error, the messages for the subform’s fields are pluralized, even though they should be singular. For example, I get

Users password doesn't match confirmation
Users password is too short (minimum is 8 characters)

instead of

User password doesn't match confirmation
User password is too short (minimum is 8 characters)

I don’t think this is an inflection issue, since “User” follows standard pluralization rules. Rather it must have to do with the use of nested attributes in a subform. In my case, the subform returns an array containing one user, but theoretically it could return data for multiple users.

How/where can I tell Rails not to pluralize when referring to only one element of an array?


Edit 3/14/2012 to show controller and view:

app/controllers/accounts_controller.rb (“New” action only):

class AccountsController < ApplicationController
  before_filter :authenticate_user!, :except => [:new, :create]
  before_filter :user_signed_out,    :only   => [:new, :create]
  load_and_authorize_resource # CanCan - does a standard load for each action, and authorizes user

  def new
    # CanCan:  @account = Account.new (and tests each attribute for ability)
    @account.users.build
    @title = "Sign Up for a New Account"
    @header = "Sign up for a new account"
  end
end

app/views/accounts/new.html.erb:

<h2><%= @header %></h2>

<%= form_for(@account) do |f| %>
  <%= render 'account_fields', :f => f %>

  <%= f.fields_for :users do |user_form| %>
    <div class="field"><%= user_form.label :email %><br />
    <%= user_form.email_field :email %></div>
    <div class="field"><%= user_form.label :password %><br />
    <%= user_form.password_field :password %></div>
    <div class="field"><%= user_form.label :password_confirmation %><br />
    <%= user_form.password_field :password_confirmation %></div>
  <% end %>

  <div class="actions">
    <%= f.submit "Create Account" %>
  </div>
<% end %>

I was trying error_messages_for inside the f.fields_for block above.

app/views/shared/_error_messages.html.erb rendered by layout before all views:

<% if object.errors.any? %>
  <div id="error_explanation">
    <h2><%= pluralize(object.errors.count, "error") %> 
      prohibited this <%= object.class.to_s.underscore.humanize.downcase %>
      from being saved:</h2>
    <p>There were problems with the following fields:</p>
    <ul>
    <% object.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% 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-05-31T12:53:54+00:00Added an answer on May 31, 2026 at 12:53 pm

    As @Marc suggested, the messages are generated based on the model. This gets tricky when accepts_nested_attributes_for is involved, as it is in my Account model:

    has_many :users, :inverse_of => :account, :dependent => :destroy
    accepts_nested_attributes_for :users
    

    To get more insight into the error object, I inserted <%= object.errors.inspect %> into _error_messages.html.erb. This showed me that the full error object is, for example:

    #<ActiveModel::Errors:0xb5c86a8 @base=#<Account id: nil, name: “”, created_at: nil, updated_at: nil>,
    @messages={:”users.password”=>[“doesn’t match confirmation”, “is too
    short (minimum is 8 characters)”], :name=>[“can’t be blank”]}>

    When Rails generates the full_messages array, it just feeds each attribute and message into the full_message method. If the attribute is “users.password”, for example, then that will simply be “humanized” (without respect to the number of objects in the array) and concatenated with the message(s) to return

    Users password doesn’t match confirmation
    Users password is too short (minimum is 8 characters)

    The crux of any solution is to avoid using full_messages:

    • Although I couldn’t get error_messages_for to work, it wouldn’t be too
      hard to write a small helper that allows specifying a custom object
      name to prepend to the message.

    • Avoid the problem of the displaying object name altogether by highlighting the
      specific field that is in error and placing the error message suffix(es) next
      to the field. This works nicely with Twitter Bootstrap and SimpleForm.

    • This article make a good case for providing explicit
      translations for each message, claiming that any attempt to
      concatenate strings is bound to cause problems.

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

Sidebar

Related Questions

Using Rails 3.1.3 with Devise 1.5.3. My app has accounts and users. Each account
I have a legacy project using Rails 2.3.5 but I can't find with which
I'm using rails 3.2. I have many to many type of models. Is there
I'm using rails 2.3.5 and devise 1.0.6. I'm having users confirm account's with email.
I'm trying to allow users that have connected their Facebook accounts to my rails
I have following tables : users accounts ( user has_one account ) pictures (
I'm using Rails and Devise gem. I want to PayPal account. I have function:
Using Rails 3.2. I have an individual Shop post, and each shop has reviews.
I have a deployment using: rails 2.3.2 ruby 1.8.7 mysql db and 3 mongrel
I have such problem: I'm using rails, devise gem and jQuery validation plugin. I

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.