Chemist Chemist - 25 days ago 6x
Sass (Sass) Question

Ruby field_with_errors doesn't @extend .control-group .error

Ok. I can't figure this out. The problem is that

is not working in css. I have css:

@import "bootstrap";

.field_with_errors {
@extend .control-group;
@extend .error;

It doesn't highlight the fields that have div class
. I can't figure out why, it worked on other apps I made. If I write in CSS something like
color: #f00;
- this works. It just doesn't
for some reason. Any ideas?


<div class="row">
<div class="span6 offset3">
<%= form_for(@problem) do |f| %>
<%= render 'shared/error_messages' %>

<%= f.label :name, raw("Your name:") %>
<%= f.text_field :name %>

<%= f.label :email, raw("E-mail address (for confirmation):") %>
<%= f.text_field :email %>

<%= f.label :description, raw("Enter a description of the problem:") %>
<%= f.text_area :description %>

<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>

Probably a dumb question, I must've missed something. I just don't know what it is and would really like this to work like it did before. Any help appreciated!

After looking at bootstrap-sass files, I realized that I am able to @extend classes that are in the files there (
@extend .form-control
works for instance). So it must be that
is not there!! Where it went I still can't figure out, unless they just changed it like a week ago. :/


I figured it out. This has to do with Twitter-Bootstrap, which has a class .alert in it. That is the class responsible for showing errors with correct styling. Bootstrap installs who knows where and is easiest to access through Developer Tools in browser (that sucks). I couldn't find where the source of the gem is located (it pointed me to folder that is not a folder). So I copied twitter css files from github directly into my app -> vendor/assets/stylesheets . Now I can deal with the problem. I changed the style of .alert class inside one of bootstrap files (_alerts.scss) and added extra classes in my custom.css.scss file to make border around inputs red on errors. Somehow this whole thing worked better in previous apps I made, I think this has to do with changes they made to bootstrap and possibly the fact that I messed with bootstrap's original design (like a full-width header). The biggest thing that led me to solution was that the class is .alert and not .error like I thought. Also big thanks to browser developer tools, I couldn't find my files without you.

Edit: Here's the download instructions on Bootstrap to get the files: