seyhunak / twitter-bootstrap-rails

Twitter Bootstrap for Rails 6.0, Rails 5 - Rails 4.x Asset Pipeline
https://github.com/seyhunak/twitter-bootstrap-rails
4.5k stars 996 forks source link

Fix error_span in form_erors_helper.rb #795

Closed lingceng closed 9 years ago

lingceng commented 10 years ago

It seems the old error_span helper does not work at all. I fix it by included in ActionView::Helpers::FormBuilder.

toadkicker commented 10 years ago

Hey can you help us out and include a test for the helper here? See https://github.com/seyhunak/twitter-bootstrap-rails/issues/774

lingceng commented 10 years ago

@toadkicker OK, I will fix #774.

araslanov-e commented 9 years ago

When merge? B)

toadkicker commented 9 years ago

It needs test coverage before we merge it in

lingceng commented 9 years ago

Sorry for late. @toadkicker I have added the test.

araslanov-e commented 9 years ago

Thanks

araslanov-e commented 9 years ago

When can update? B) P.S. Updated now, but no change

lingceng commented 9 years ago

Make sure you use the master version as following:

gem 'twitter-bootstrap-rails' git:'https://github.com/seyhunak/twitter-bootstrap-rails.git'

And you may change the error_span usage as following:

f.error_span :title

araslanov-e commented 9 years ago

I use just gem 'twitter-bootstrap-rails', without git B)

toadkicker commented 9 years ago

gem 'twitter-bootstrap-rails' :git => 'https://github.com/seyhunak/twitter-bootstrap-rails.git', :branch => 'master'

araslanov-e commented 9 years ago

OK

lingceng commented 9 years ago

@toadkicker Do you mean making error_span an empty helper? I did not find a way to make error_span(@foo[:attrib]) work as we wish.

araslanov-e commented 9 years ago

I am update gem, and ...

ActionController::RoutingError (No route matches [GET] "/assets/fonts/fontawesome-webfont.woff")
lingceng commented 9 years ago

@araslanov-e

Your problem discussed at #789

Try to config following in your bootstrap.css.less to fix for now.

// Font Awesome
@import "fontawesome/font-awesome.less";

// Set the Font Awesome (Font Awesome is default. You can disable by commenting below lines)
@fontAwesomeEotPath: font-url("fontawesome-webfont.eot");
@fontAwesomeEotPath_iefix: font-url("fontawesome-webfont.eot?#iefix");
@fontAwesomeWoffPath: font-url("fontawesome-webfont.woff");
@fontAwesomeTtfPath: font-url("fontawesome-webfont.ttf");
@fontAwesomeSvgPath: font-url("fontawesome-webfont.svg#fontawesomeregular");

@font-face {
  font-family: 'FontAwesome';
  src: @fontAwesomeEotPath;
  src: @fontAwesomeEotPath_iefix format('embedded-opentype'),
       @fontAwesomeWoffPath format('woff'),
       @fontAwesomeTtfPath format('truetype'),
       @fontAwesomeSvgPath format('svg');
  font-weight: normal;
  font-style: normal;
}
toadkicker commented 9 years ago

@lingceng because form_for accepts an array of objects the helper needs specificity of which object to observe. In you're test you're calling self which is in scope of the test, but in the context of the rails app it is lost. If there's a better way to get around self.object in the helper feel free to give it a try, but I'm fairly certain ruby wants it this way.

araslanov-e commented 9 years ago

@lingceng thanks

toadkicker commented 9 years ago

I fixed this in railsstrap if you are interested, use it.

araslanov-e commented 9 years ago

@toadkicker thanks, used railsstrap

morkevicius commented 9 years ago

@toadkicker +1

leckylao commented 9 years ago

I am using the current master branch and the helper doesn't work

undefined local variable or method `object' for #<#Class:0x007fd2b87185a8:0x00000002e8b730> Extracted source (around line #16):

def errors_on?(attribute)
  object.errors[attribute].present? if object.respond_to?(:errors)
end 
lingceng commented 9 years ago

@leckylao

Make sure your f.error_span(:hello) in a form_for tag, eg.

= form_for @card, html: { class: "form card" } do |f|
  .form-group
    = f.label :question, class: 'control-label'
    = f.text_area :question, class: 'form-control rc-card-question', required: true, rows: '2'
    = f.error_span(:question)

Note that, the demo code above is using haml.

leckylao commented 9 years ago

Thanks @lingceng. It made sense