Andrew Colclough

Web Design & Dev., Liberty, Economics, Football

Rails 3 and Restful Authentification Routing Error?

I was trying to set up a plugin for Rails (v.3) called Restful Authentication and I was getting the following routing error:

"Routing Error uninitialized constant ApplicationController::AuthenticatedSystem"

Luckily, found a tip here by user 'Croplio' that worked for me.

Try the following in your application_controller.rb file:

class ApplicationController < ActionController::Base
  require File.join(Rails.root, 'lib', 'authenticated_system.rb')
  include AuthenticatedSystem
end
Score.

Filed under  //   AutheticatedSystem   ERROR   Restful Authentification   coding   rails 3   routing   ruby   tip  

Sublime: ...A Color Picker like Textmate?

Yeah, another feature that I (a CSS designer/dev) cannot live without. If you have no idea what I am talking about, here's the skinny:

Usually, as I am working on rapid development - I need to quickly pick colors - and test how they mesh with my design. Well, I don't know about you - but I don't do instant Hex or RGBa color conversions in my head too quickly. So, one of my favorite features of TextMate is the command "Insert Color" - Invoked by hitting Command+Shift+C. This launches the Apple color wheel picker that I use to adjust ranges of color -> which then spits out a Hex or RGBa value into my CSS code. 

Colorpicker

Sublime Text 2 doesn't have anything like this (as of yet...), and for me - that really could slow down my workflow. However - I found a decent solution until (or if) Sublime gets something like this. 

First: Nab the application version of the Apple Color Picker

This will allow you to keep open the color picker while you are working.

Second: Download and install either or both:

Colors

Simply drop these plugin files into Library > ColorPickers (create this dir/ if it doesn't exist). Then restart the Color Picker Application - and you have a way to easily grap Hex or RGBa values and dump them into Sublime. Win!

Note - Obviously, this is for OSX users. If you are on Windows, you will have to hunt around for windows variations of these little apps. 

Also - the TextMate command is just a ruby script...so if anyone has the know-how to convert it to something Sublime could understand...

Insertcolor
And if you had the same question I did about the above screenshot...

Burlywood

Filed under  //   Color Picker   Sublime Text 2   Textmate   burlywood   coding   css   hex   tips  

Start using HTML5 Now - Compatible with FF, Safari, IE6-9

So, I can use this now?

Actually, yes, with a few extra steps. And it will work in all modern browsers. It can even work in IE6. There are only a few little quirks we need to get past if we’re going to start using this today.

First, because most browsers don’t understand the new HTML5 doctype, they don’t know about these new tags in HTML5. Fortunately, due to the flexibility of browsers, they deal well with unknown tags. The only issue here is unknown tags have no default style, and are treated as inline tags. These new HTML5 tags are structural, and should obviously be block level elements. So, when we style them with CSS, we need to be sure to include display:block; in our attribute/value pairs.

Include this simple extra piece of CSS, and these new tags are immediately usable. Starting today. And of course, once HTML5 is more widely supported, the superfluous display:block; can be removed, as it will be included in the browser default styles.

Supporting IE

There is one more issue if you require IE support. Turns out that the IE rendering engine will work with the new tags, but will not recognize any CSS applied to them. Well, that’s no good. Fortunately, IE just needs a good swift kick with the help of a very simple bit of JavaScript. All we need to do to kick start IE is to create a DOM node with JavaScript for each of the new tags, and suddenly IE will apply styles to the new tags with no problem. The code will look something like this, and can be placed directly in the head of our document, or the contents of the script tag placed into an external file and included.

<script>
  document.createElement('header');
  document.createElement('footer');
  document.createElement('section');
  document.createElement('aside');
  document.createElement('nav');
  document.createElement('article');
</script>

Before we leave this code, there’s one thing to mention about the script tag in HTML5. HTML5 will assume type="text/javascript" on any script element, so it need not be included. Once again, making things simple.

Wrapping Up

So we can begin, right now, to structure our documents using the new tags provided in HTML5. With a few simple tricks, they’ll work today, and be compatible in the future. So next time you start a new site, consider going with HTML5, and give your markup a little more defined structure.

I have tested this and was surprised that it does appear to be fully compatible.

Filed under  //   coding   compatible   html5   internet explorer   tags   web design   web developement  

Behold - the awesome power of Sass Mixins

In case you missed this post, I have started using the Compass and Sass CSS frameworks on a new project. I wanted to share a little magical Sass action that I came across while working on a new site.

A Browser-wide Opacity Mixin

Probably the most outstanding feature of Sass is the ability to create "mixins." A mixin is nothing more than a small block of styling code that you create once - and then simply call out later (similar to calling a function in javascript). Sass' Mixin's can preform many actions that you would expect from a normal programming  language such as accepting parameters, variables, and even preforming those 'hard' maths. I happened to create a simple mixin that uses all three of these features to render a desired opacity across all browsers (hat-tip: Chris Coyier for the cross-browser opacity code). 

As Chris pointed out, each browser accepts opacity styles in a slightly different way. (I know, you're shocked...shocked!!) With regular CSS - you have two options: 

1) Create a .transparent_class and apply this to all html elements you wish to apply the opacity shift to. While this works, it is somewhat undesirable - because you are adding specific style information into your markup. In effect, to add/remove a design aspect you would need to alter your markup - when the ultimate goal is to separate the markup/structure from the style/design.

2) Apply all 4 opacity style rules to each individual element you select through CSS. This is technically better, but obviously a pain in the butt, and can really muck up your CSS. Unless you use a code editor such as Textmate which supports code snippets - you will be failing to keep your code DRY (Don't Repeat Yourself).  

As a side note, don't feel bad if you happen to use either of these methods. Coding ideals are just that: ideals. Coding ideals are often nice (though lofty) goals that will spare you headaches over time. However, in my experience - the difficulty and time involved coding rises exponentially the more rigidly you attempt to adhere to a coding ideal. 

But there is good news. The Sass Framework can greatly help in this department.

Here is the Sass Mixin I created for opacity:

Declaring the Mixin:

Mixin

Explanation:
The first line is the mixin name that you will refer to later, followed by the actual opacity parameter variable.
The next several lines are each of the 4 browser opacity style rule variations. Each one refers to the !opacity variable that you will pass the mixin. Because Internet Explorer takes the parameter in a different format (e.g. IE: 50, Others: 0.5 ) - I use a little simple math to calculate the value. Zing!

(By the way - the strange format is just one of the ways to write Sass code. You can read more about that on the Sass website.)

Calling the Mixin:

Mixincall

Explanation:
To call the mixin, all I have to do is add +opacity rule and pass the actual value I want inside the parentheses.  (note: the +shadow line is calling another mixin I created that accepts many parameters)

Sass code is then compiled to CSS (in this case, automatically by compass anytime I save a change) and adds...

filter: alpha(opacity= !opacity * 100); -moz-opacity: 0.7; -khtml-opacity: 0.7; opacity: 0.7;

...to the class .book-shadow, or anyplace else I call +opacity.

With Sass - it allows me to have the best of methods 1 and 2, which I mentioned above. I don't have to add design specific classes into my markup, as in method #1. Also - if I want a different opacity value, I don't have to create a separate .transparency_lighter_class, for example. I simply pass a different value. Sass also cuts out the suck of method #2, because I only have to repeat the one rule +opacity(howMuch) to any element.

Now - you do still end up with repetitive rules in your CSS files anytime you call +opacity - but you don't have to deal with them. Plus, Sass can be told to compile your CSS into a variety of modes, from expanded - to compact, which will trim down the size of your CSS, if you want it to.

Mixins are just one of the many great features of Sass. So far, my workflow has been greatly enhanced, and that's a Win in my book. 

Happy coding.

-Adc

Filed under  //   Chris Coyier   DRY   coding   compass   css   framework   mixin   opacity   sass   tips