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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:44:45+00:00 2026-05-13T00:44:45+00:00

I have the following simple form: <% form_for(@weight) do |f| %> <%= f.error_messages %>

  • 0

I have the following simple form:

<% form_for(@weight) do |f| %>
  <%= f.error_messages %>
  <%= f.label :weight %>:
  <%= f.text_field :weight, :size => 5 %> kg.
  <%= f.submit "Add weight" %>
  <%= f.error_message_on :weight %>
<% end %>

which displays a form of only one field: weight.

Normally it renders like this:

<form action="/weights" class="new_weight" id="new_weight" method="post">
  <div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="jYoVJkDnv4a1DMGnelJpGPElbH0XWKPNlESTt9GvzdA=" /></div>

  <label for="weight_weight">Weight</label>:
  <input id="weight_weight" name="weight[weight]" size="5" type="text" /> kg.
  <input id="weight_submit" name="commit" type="submit" value="Add weight" />
</form>

which is fine. When I submit this form without setting any weight I get a validation error. f.error_messages and f.error_messages_on :weight correctly display the error messages, but the label and text field are not surrounded in a div with the class fieldWithError as I normally expect in forms in Rails. I instead get this:

<form action="/weights" class="new_weight" id="new_weight" method="post">
  <div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="jYoVJkDnv4a1DMGnelJpGPElbH0XWKPNlESTt9GvzdA=" /></div>

  <div class="errorExplanation" id="errorExplanation">
    <h2>1 error prohibited this weight from being saved</h2>
    <p>There were problems with the following fields:</p>
    <ul><li>Weight can't be blank</li></ul>
  </div>

  <label for="weight_weight">Weight</label>:
  <input id="weight_weight" name="weight[weight]" size="5" type="text" /> kg.
  <input id="weight_submit" name="commit" type="submit" value="Add weight" />

  <div class="formError">can't be blank</div>
</form>

For reference, what I’ve should have gotten is this:

<form action="/weights" class="new_weight" id="new_weight" method="post">
  <div style="margin:0;padding:0;display:inline"><input name="authenticity_token" type="hidden" value="jYoVJkDnv4a1DMGnelJpGPElbH0XWKPNlESTt9GvzdA=" /></div>

  <div class="errorExplanation" id="errorExplanation">
    <h2>1 error prohibited this weight from being saved</h2>
    <p>There were problems with the following fields:</p>
    <ul><li>Weight can't be blank</li></ul>
  </div>

  <div class="fieldWithErrors"><label for="weight_weight">Weight</label></div>:
  <div class="fieldWithErrors"><input id="weight_weight" name="weight[weight]" size="5" type="text" /></div> kg.
  <input id="weight_submit" name="commit" type="submit" value="Add weight" />
  <div class="formError">can't be blank</div>
</form>

Any ideas why I don’t get those divs? I have formtastic installed and it’s in use in other forms, but as far as I know that shouldn’t interfere with this form.

Update: just to be sure, I printed out debug(@weight), it has the errors:

--- &id002 !ruby/object:Weight 
attributes: 
  created_at: 
  updated_at: 

  weight: 
  measured_on: &id001 !timestamp 
    at: "2009-11-22 01:30:13.522589 +01:00"
    "@marshal_with_utc_coercion": false
  user_id: 1
attributes_cache: 
  measured_on: *id001
changed_attributes: 

  measured_on: 
  user_id: 
errors: !ruby/object:ActiveRecord::Errors 
  base: *id002
  errors: 
    weight: 
    - !ruby/object:ActiveRecord::Error 
      attribute: :weight

      base: *id002
      message: :blank
      options: {}

      type: :blank
new_record: true

Update: the model is

class Weight < ActiveRecord::Base
  belongs_to :user
  validates_presence_of :weight, :measured_on
  attr_accessible :weight, :measured_on

  def after_initialize
    self.measured_on ||= Time.now
  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-05-13T00:44:45+00:00Added an answer on May 13, 2026 at 12:44 am

    This is a bug in Formtastic. It was fixed but it seems that at this moment no released version of Formtastic has the fix.

    My own bug report is on http://github.com/justinfrench/formtastic/issues/closed/#issue/132

    The fix can be seen on http://github.com/grimen/formtastic/commit/2b81d9af385dadf8b37dc14f387afe3d43e4958a

    Ultimately the problem was using justinfrench-formtastic from github, which is outdated and abandoned instead of formtastic from gemcutter.

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

Sidebar

Related Questions

I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which
I have a really simple search form with the following Label (Search) Textbox (fixed
i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
In the Photo model I have following simple rule: searchable do string :note end
I have simple form set up like the following: <form> <input type=text name=first_number id=first_number
I have the following very simple form: <asp:UpdatePanel ID=ClaimRewardsForm runat=server> <ContentTemplate> <span class=largeBold>Select jacket
I have a simple form I created, and in it I have the following
as you can see in the following image, i have a simple form that
I have following simple class: @interface Article: NSObject { NSString *title; } @property (copy,
I have following simple program: import std.stdio; int main(string[] argv) { writeln(Hello, world!); return

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.