ActionView::Base.field_error_proc doesn't call for label tag #2492

Closed
kryzhovnik opened this Issue Aug 11, 2011 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

kryzhovnik commented Aug 11, 2011

ActionView::Base.field_error_proc doesn't call for label tag

The bug is observed when three conditions

  1. The object that pass to form_for doesn't linked with conventionally named instance variable. For example we could have @author = User.new

  2. Second argument of form builder's label method is a Hash

    <%= f.label :author_name, :class => 'label' %>
    
  3. Field is invalid

Example:

app/controllers/users_controller.rb

    class UsersController < ApplicationController
      ...
      def new
        @author = User.new
        ...
      end
      ...
    end

app/users/_form.html.haml

    <%= form_for(@author) do |f| %>
      ...
      <div class="field">
        <%= f.label :name, :class => 'label' %><br />
        <%= f.text_field :name %>
      </div>
      ...
    <% end %>

Expected output:

<div class="field"> 
  <div class="field_with_errors"><label class="label" for="user_name">Name</label><br /></div>
  <div class="field_with_errors"><input id="user_name" name="user[name]" size="30" type="text" value="" /></div>
</div>

And what we've got now:

<div class="field"> 
  <label class="label" for="user_name">Name</label><br /> 
  <div class="field_with_errors"><input id="user_name" name="user[name]" size="30" type="text" value="" /></div> 
</div> 

@kryzhovnik kryzhovnik added a commit to kryzhovnik/rails that referenced this issue Mar 27, 2012

@kryzhovnik kryzhovnik Fixing issue #2492. ActionView::Base.field_error_proc doesn't call fo…
…r label.

objectify_options method should be applied to the proper options arg.

See explanation and example of the bug - https://github.com/kryzhovnik/rails_field_error_proc_bug_example
7111133

@kryzhovnik kryzhovnik added a commit to kryzhovnik/rails that referenced this issue Mar 27, 2012

@kryzhovnik kryzhovnik Fixing issue #2492 for master branch. ActionView::Base.field_error_pr…
…oc doesn't call for label.

objectify_options method should be applied to the proper options arg.

See explanation and example of the bug - https://github.com/kryzhovnik/rails_field_error_proc_bug_example
6ce0a6d

@rafaelfranca rafaelfranca added a commit to rafaelfranca/omg-rails that referenced this issue Mar 27, 2012

@rafaelfranca rafaelfranca Check if the options hash already exists and merge it with the another
hash.

Closes #2492 and #5614
6968bc1

jeremy closed this in 32763a8 Mar 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment