The dangers of url_for in Rails applications
In a great post about named routes in Rails, path vs. url, Viget Labs ponders which variant is best used.<br />
<br />
Most often we use foo_path, which when used in Rails URL helpers will generate a relative path, where foo_url generates a full URL. In most cases the path makes most sense, but not always.
Make box shadows look the same in IE and other browsers
The box shadows created rendered in IE by CSS3PIE look darker and are blurred differently than in browsers that render box-shadow
natively.
If possible, try to be OK with this. If not, make an IE-only stylesheet that uses a different color and blur radius:
// Real browsers:
+box_shadow("0 4px 10px #bbb")
// IE with PIE:
+box_shadow("0 5px 15px #888")
We should try to package this solution in a neat way so we don't need different stylesheets.
See also this [cross-browser box-shadow comparison]...
Scope to records with a given state in state_machine
The state_machine gem ships with a scope with_state
. This scope has some problems in complex queries or scope chains.
Use this instead:
named_scope :having_state, lambda { |*state_or_states|
state_or_states = Array.wrap(state_or_states).map(&:to_s)
{ :conditions => [ 'articles.state IN (?)', state_or_states ] }
}
If you want a scope with hash options (with the side effects you should know about):
named_scope :having_st...
Fighting the @font-face FOUT « Paul Irish
Cached fonts WILL caused an unstyled flash of text.
Bundler for Rails 2.3.x
Update RubyGems and Passenger
Bundler requires Rubygems >= 1.3.6. Run gem update --system
if you have an older version.
It also is not compatible with older versions of passenger, so bring that up to date as well (2.2.15 works).
If you installed RubyGems through apt (which you should never do!), you may see a message giving you a hint to use apt to update.
Some people advise to install the 'rubygems-update-1.3.7' gem on Ubuntu systems if you used apt to install RubyGems.
I did that - and lost all...
Disable Rails XSS protection in ActionMailer views
This might eventually be fixed by Rails itself.\
Right now this is the way to have the rails_xss plugin not escape the body of ActionMailer mails.
Put this into config/initializers/mailers_without_rails_xss.rb
:
Use the same template for multiple ActionMailer actions
One option is to use partials. Or you can set the @template
field to the name of another action:
class Mailer < ActionMailer::Base
def foo
subject "Hello World"
end
def bar
subject "Hello Universe"
@template = 'foo'
end
end
Recursively remove unnecessary executable-flags
Sometimes files attain executable-flags that they do not need, e.g. when your Windows VM copies them over a Samba share onto your machine.
From inside your Rails project directory call regularly:
geordi remove-executable-flags
Runs chmod -x
on Ruby, HTML, CSS, image, Rake and similar files.
This script is part of our geordi gem on github.
Hide the last bottom margin in a container
When you create e.g. a sidebar box that contains headlines and paragraphs, the final paragraph's margin in that box will create an undesired 'bottom padding' inside that box.
Here is a Sass mixin that you can apply to such boxes. It makes the last child's bottom margin disappear:
=hide_last_margin
>*:last-child
margin-bottom: 0
Use it like this:
.sidebar_box
p, table, ul
margin-bottom: 1em
+hide_last_margin
Internet Explorer (fix)
Does not work in versions of <IE8
Your best bet is to expli...
Linux: create a symbolic link
You may omit the /path/to/link_name
to have a link with the same filename appear in the current directory
ln -s /path/to/file /path/to/link_name
unlink link_name // to remove the link and not where it is pointing at
Vadikom » Poshy Tip - jQuery Plugin for Stylish Tooltips
With this plugin, you can create a scalable tooltip by just using a single background image for the tooltip body.
Prototip 2 - Create beautiful tooltips with ease
Prototip allows you to easily create both simple and complex tooltips using the Prototype javascript framework.
Please note: "Permission to use Prototip on your domain is required and can be obtained by paying a small fee."
Programming Things I Wish I Knew Earlier
The point is, evented I/O is not magic scalability pixie dust, and like anything, there is a tradeoff.
Boolean attributes and pretty enumerations in Cucumber Factory 1.7
Boolean attributes can now be set by appending "which", "that" or "who" at the end:
Given there is a movie which is awesome
And there is a movie with the name "Sunshine" that is not a comedy
And there is a director who is popular
Instead of "and" you can now also use "but" and commas to join sentences:
Given there is a movie which is awesome, popular and successful but not science fiction
And there is a director with the income "500000" but with the account balance "-30000"
Update with `sudo gem install cucumber_facto...
Spec correct routing of custom URLs
When you roll custom URLs with hacks like routing-filter, you can put a spec like this into spec/routing/routing_spec.rb
:
jQuery autocomplete with multiple values
This will eventually be integrated into jQuery UI with the multiple: true
option, but right now this is the way. Credits go to jqueryui.com.
Testing validates_format_of with Shoulda matchers
Don't use should validate_format_of(...)
because that matcher works in weird ways. Use the allow_value
matcher instead:
describe Email, '#sender' do
# > Rspec 3 should syntax
it { should allow_value("email@addresse.foo").for(:sender) }
it { should_not allow_value("foo").for(:sender) }
# Rspec 3 expect syntax
it { is_expected.to allow_value("email@addresse.foo").for(:sender) }
it { is_expected.not_to allow_value("foo").for(:sender) }
end
Errors that may occur if you do use should validate_format_of(...)
:
...
Get rid of US keyboard layout
Problem:
Keyboard layout reverting to US on (every) reboot
Cause:
I found the same problem, but only on my wife's account. I'd set her keyboard layout to UK through Gnome preferences and every time the US layout would reappear and be selected frustratingly.\
It turned out that on the gdm login screen her choice of keyboard layout in the discreet option bar at the bottom of the screen was set to US. That was then overriding the Gnome layout preference.
Solution:
Selecting the appropriate keyboard layout on the next login solved the...
schacon's showoff at master - GitHub
the best damn presentation software a developer could ever love
Regular Expressions - Cheat Sheet
You can write regular expressions some different ways, e.g. /regex/
and %r{regex}
. For examples, look here.
Remember that it is always a good idea to match a regex visually first.
Characters
Literal Characters
[ ] \ ^ $ . | ? * + ( )
Character Classes
[ae] matches a and e, e.g. gr[ae]y => grey or gray => but NOT graay or graey
[0-9] ...
Default implementation of resource_controller actions
jamesgolick / resource_controller at Github
module ResourceController
module Actions
def index
load_collection
before :index
response_for :index
end
def show
load_object
before :show
response_for :show
rescue ActiveRecord::RecordNotFound
response_for :show_fails
end
def create
build_object
load_object
before :create
if object.save
...
Run a POP3 server on a directory of mail files with popthis
popthis is awesome when used with inaction_mailer.
Install the gem:
sudo gem install popthis
Start the server:
popthis tmp/sent_mails/ # e.g. the folder containing the .txt-mails generated by inaction_mailer
Now, configure your mail client as follows:
Server: localhost
Protocol: POP3
Port: 2220
Username: anything
Password: anything
Task Switch in Linux Console
To pause and send a task to the background
ctrl+z
to reactivate the task
fg
to run task in background
bg
to see a list of so running tasks
jobs