Skip to content

Instantly share code, notes, and snippets.

@bogdanconstantinescu
Forked from t2/application.rb
Created May 9, 2012 15:26
Show Gist options
  • Select an option

  • Save bogdanconstantinescu/2645498 to your computer and use it in GitHub Desktop.

Select an option

Save bogdanconstantinescu/2645498 to your computer and use it in GitHub Desktop.

Revisions

  1. bogdanconstantinescu revised this gist May 10, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion application.rb
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input, textarea, select"

    form_fields = [
    'textarea',
    'input',
    'select'
    ]

    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, " + form_fields.join(', ')

    elements.each do |e|
    if e.node_name.eql? 'label'
  2. bogdanconstantinescu revised this gist May 9, 2012. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,18 @@
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input, textarea"
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input, textarea, select"

    form_fields = [
    'textarea',
    'input',
    'select'
    ]

    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="control-group error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input' or e.node_name.eql? 'textarea'
    elsif form_fields.include? e.node_name
    if instance.error_message.kind_of?(Array)
    html = %(<div class="control-group error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
  3. bogdanconstantinescu revised this gist May 9, 2012. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    end
    html
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input, textarea"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="control-group error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input' or e.node_name.eql? 'textarea'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="control-group error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="control-group error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    end
    html
    end
  4. @t2 t2 revised this gist Dec 12, 2011. 1 changed file with 16 additions and 18 deletions.
    34 changes: 16 additions & 18 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,17 @@
    class Application < Rails::Application
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    end
    html
    end
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    end
    html
    end
  5. @t2 t2 revised this gist Dec 12, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion application.rb
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ class Application < Rails::Application
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error" style="display:inline;">#{e}</div>).html_safe
    html = %(<div class="clearfix error">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
  6. @t2 t2 renamed this gist Dec 12, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion form.css.scss → your_controller.css.scss
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // Place all the styles related to the UserProfiles controller here.
    // Place all the styles related to the YourController controller here.
    // They will automatically be included in application.css.
    // You can use Sass (SCSS) here: http://sass-lang.com/

  7. @t2 t2 revised this gist Dec 12, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion form.css.scss
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,5 @@
    // You can use Sass (SCSS) here: http://sass-lang.com/

    form .clearfix:before, form .clearfix:after {
    display: inline;
    display: inline;
    }
  8. @t2 t2 revised this gist Dec 12, 2011. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,19 @@
    class Application < Rails::Application
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error" style="display:inline;">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error" style="display:inline;">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    html
    end
    html
    end
    end
  9. @t2 t2 created this gist Dec 12, 2011.
    19 changes: 19 additions & 0 deletions application.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    class Application < Rails::Application
    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
    html = %(<div class="field_with_errors">#{html_tag}</div>).html_safe
    # add nokogiri gem to Gemfile
    elements = Nokogiri::HTML::DocumentFragment.parse(html_tag).css "label, input"
    elements.each do |e|
    if e.node_name.eql? 'label'
    html = %(<div class="clearfix error" style="display:inline;">#{e}</div>).html_safe
    elsif e.node_name.eql? 'input'
    if instance.error_message.kind_of?(Array)
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message.join(',')}</span></div>).html_safe
    else
    html = %(<div class="clearfix error">#{html_tag}<span class="help-inline">&nbsp;#{instance.error_message}</span></div>).html_safe
    end
    end
    end
    html
    end
    end
    7 changes: 7 additions & 0 deletions form.css.scss
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // Place all the styles related to the UserProfiles controller here.
    // They will automatically be included in application.css.
    // You can use Sass (SCSS) here: http://sass-lang.com/

    form .clearfix:before, form .clearfix:after {
    display: inline;
    }