going through p2_0 and found that the rails31/depot_b/app/assets/stylesheets/products.css.scss would refuse to load. Need to remove the top 3 comment lines or use /* */ instead of // for it to work.
I don’t see that problem here. I will also note that those three lines are generated by Rails.
I’ve followed this part of the book through 3 times now, and the product styles aren’t working for me either. Since Steve suggested it worked after changing the comment lines, I tried that assuming maybe the file just needed to be touched or something. I’m still not seeing styles on the product index, but the source shows the generated stylesheet being loaded,
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <link href="/assets/products.css?body=1" media="screen" rel="stylesheet" type="text/css" /> <link href="/assets/scaffolds.css?body=1" media="screen" rel="stylesheet" type="text/css" />
The only thing that seems weird is that there’s no reference to a .products class anywhere in the products/index.html.erb, but the class definitions are nested under a .products class. If I add the products class to the line_item_even and line_item_odd in the cycle, those dt’s get the styling. Adding the products class to other elements in that file don’t do anything.
The versions of sass installed with rails 3.1.0 are:
sass (3.1.7) sass-rails (3.1.0)
I think that as it happened to me you have missed the line <body class='<%= controller.controller_name %>'> present on page 74 (PDF version) where application.html.erb is presented.
Ramon Maria Gallart
I downloaded the code from the link under the book image above yesterday, and I don’t have an ‘assets’ folder under ‘app’ in the depot_b folder, as shown on page 72. I think the new asset code examples are not fully baked yet. Also, Ramon found the referenced <%=controller.controller_name %> line in the pdf, but not in the depot_b/app/assets folder, since I don’t have the folder at all.
Thanks, Ramon. I kept skimming over that part since there wasn’t one of those indicator arrows in the sidebar. I guess I need to pay more attention. :D
I followed the book every step of the way and the modified products.css.scss (downloaded from the link in the ebook) loads (I guess it loads because rails server does not throw any error) but it fails to render (the style is not applied to the products page).
As the OP suggested, deleting the three comment lines starting with “//” fixed this. You might want to modify the downloadable products.css.scss file to reflect that (or investigate further - I am on Win 7 x64, Ruby 1.9.3p0, rails 3.2.0, sass 3.1.12).
CSS, SCSS, SASS, … the double-slash comments that appear in products.css.scss are syntactically incorrect and should be removed, for sure.
The double slash comments are generated by Rails, and are valid SCSS:
For some reason removing the double slash comments worked for me as well. Maybe some other hidden character in this file?
UPDATE: I indeed opened the file in VIM, removed the double slashes, typed them in again and saved the file and it works.
I cant even find the “assets” folder inside app folder. It is NOT there . I downloaded the source code that was in .tar format.
I encountered the same issue after downloaded the code from the website and replaced the products.css.scss with the one Rails Scaffold generated for me, and that css file simply does not load. Found here and tried every method including remove the first comments or replace // with /*, everything works. Then finally I believe that Scott is right, we just need to “touch” the file to make it recognized by Rails. The reason is straight forward, the file we downloaded from network, their last modified data will be definitely earlier than the one Rails generated for us, so Rails is simply not re-loading it even we restarted the Rails Server. Maybe the author can confirm this and make necessary comment in the book, cause I think most readers will follow the same step (copy the long css code from network to replace the local one), and encounter the same issue.
Jinhui: that makes a lot of sense. Can I ask how you copied the file, and what operating system you use? I ask because I see Roberto mentioning vim which is uncommon on Windows, and I know that the cp command (by default) will give you a fresh time stamp. I’d need to investigate further to see what happens on Windows.
But in any case, you are right: Rails indeed won’t reload if the mtime is either unchanged or at an earlier point in time:
Thanks Sam. I’m using Windows 7 Home version (32bit), and copied the file by just dragging it from WinRAR (with the zip file opened) to the target folder. And thanks to those advocators I’m also using gvim in Win, although still not quite familiar with it.
OK, I’m adding a paragraph to the “How to Read this Book” section in the Introduction (as this is where the download link is present), and I’m adding a paragraph to this point in section 6.2 as it is the point at which most people will discover this.