Submit a form with Prototype
For example, to send a form and populate a preview div with the response.
$('content_form').request({
parameters: { 'preview': "1" }, // overrides parameters
onComplete: function(transport){
$('previewContent').update(transport.responseText);
}
});
Autofocus a form field with HTML5 or jQuery
In Webkit you can use the HTML5-attribute autofocus
:
= form.text_field :title, :autofocus => 'autofocus'
Here is a jQuery fallback for browsers that don't speak HTML5:
var Autofocus = {
supported: function() {
return 'autofocus' in document.createElement('input');
},
fake: function() {
$('[autofocus]').focus();
},
extend: function() {
Autofocus.supported() || Autofocus.fake();
}
};
$(Autofocus.extend);
Cucumber Webrat steps
Most of these will not work in newer projects because these use the Capybara/Rack::Test combo in lieu of Webrat.
Find input fields
Then /^there should be a "([^"]+)" field$/ do |name|
lambda { webrat.current_scope.send(:locate_field, name) }.should_not raise_error(Webrat::NotFoundError)
end
Then /^there should be no "([^"]+)" field$/ do |name|
lambda { webrat.current_scope.send(:locate_field, name) }.should raise_error(Webrat::NotFoundError)
end
Find html content
Then /^I should see "([^\"]*)...
Release gem; Deploy gem; Update a gem created with Jeweler
Until May 2011 our gems have been created with Jeweler, which is a helper library to package code into a gem. You know a gem was cut with Jeweler if you see the word jeweler
in a gem project's Rakefile
.
This note describes how to update a gem that was cut using Jeweler. Note that this can be traumatic the first time. It would be great to have an easier workflow for this. Jeweler is deprecated these days because you can
**now [cut gems more easily using Bundler](https://makandracards.com/makandra/1229-updat...
Aggregated RSpec/Cucumber test coverage with RCov
With defaults, RCov doesn't work the way you how you would like it to. To create a nice test coverage report, copy the attached file to lib/tasks/rcov.rake
. After that rake rcov:all
will run all RSpec examples and Cucumber features. The report will be written RAILS_ROOT/coverage/index.html
.
Here is what the task does in detail:
- Generates aggregated coverage of both RSpec and Cucumber
- Works with Rails 2 and Rails 3
- Reports for
app/**/*.rb
and nothing else - If called with an environment variable
IGNORE_SHARED_TRAITS=true
it ...
Parse XML or HTML with Nokogiri
To parse XML-documents, I recommend the gem nokogiri.
A few hints:
-
xml = Nokogiri::XML("<list><item>foo</item><item>bar</item></list>")
parses an xml string. You can also callNokogiri::HTML
to be more liberal about accepting invalid XML. -
xml / 'list item'
returns all matching nodes;list item
is used like a CSS selector -
xml / './/list/item'
also returns all matching nodes, but.//list/item
is now an XPath selector- XPath seems to be triggered by a leading
.
...
- XPath seems to be triggered by a leading
Automatically build sprites with Lemonade
How it works
See the lemonade descriptions.
Unfortunately, the gem has a few problems:
- it does not work with Sass2
- it always generates all sprites when the sass file changes, which is too slow for big projects
- it expects a folder structure quite different to our usual
All these problems are solved for us, in our own lemonade fork. This fork has since been merged to the original gem, maybe we can use t...
Convert Haml to ERB
This is about converting Haml to ERB and not the other way round which you probably want!
This process can not be automated 100%, but you can still save time.
First do
script/plugin install http://github.com/cgoddard/haml2erb.git
Then in the console type
hamls = Dir["app/views/**/*.haml"] - ['app/views/layouts/screen.html.haml'];
hamls.each do |haml|
puts haml
erb = haml.sub(/\.haml$/, '.erb')
File.open(erb, 'w') do |file|
file.write Haml2Erb.convert(File.read(haml))
end
end
After th...
Typical .gitignore
log/*
tmp/*
storage/*
db/*.sqlite3
db/schema.rb
db/structure.sql
public/system
.project
.idea/
public/javascripts/all*
public/stylesheets/all*
public/stylesheets/*.css
config/database.yml
*~
*#*
.#*
.DS_Store
webrat-*.html
capybara-*.html
rerun.txt
coverage.data
coverage/*
dump_for_download.dump
.~lock.*
.*.swp
C:\\nppdf32Log\\debuglog.txt
Configuring Git with .gitconfig
Basic configuration
Please keep this config simple. It should be a starting point for new developers learning Git.
[user]
name = Your Name
email = your.name@domain.com
[branch]
sort = -committerdate
[color]
ui = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
whitespace = white reverse
meta = blue reverse
frag = blue reverse
old = red
new = green
[color "status"]
added = green
changed = yellow
untracked = cyan
[interactive]
singlekey = true # Do not requir...
Slugs with FriendlyId
Gem to provide nice looking urls ("/blog/the-greatest-bug-i-never-fixed"). If you don't need anything too special (like i18n for the urls) it works as a drop-in-replacement. It basically overwrites #to_param
to return the slug, and .find
to search by the slug.
Make sure, everywhere you build paths, you use model_path(:id => model)
instead of model_path(:id => model.id)
. You also need to adapt all code using something like .find_by_id
. The regular .find
is fine.
See the github README for installation instructions.
Don't forget ...
Sanitize: A whitelist-based Ruby HTML sanitizer
Given a list of acceptable elements and attributes, Sanitize will remove all unacceptable HTML from a string.
Bill de hÓra: Managing large stories on agile projects
I've seen this granularity problem on every project, product or program I've worked on. Often in non-agile methods it comes it up in the form of traceability requirements on top of the actual requirements.
clemens's later_dude at master - GitHub
LaterDude is a small calendar helper with i18n support
Reflective Surface » Tests: Pragmatism or ideology?
The argument that using tests is a ideologic waster of time fails when one considers how it can help to insure architectural decisions.
mca blog [REST Upside Down]
i keep looking for ways to help people 'get' REST. not URLs or HTTP Methods; but REST itself - in a nutshell. so here's a new angle i've started playing with: "REST Upside Down."
Recreating the button | stopdesign
Until some future version of HTML gives us new native controls to use in a browser, at Google, we’ve been playing and experimenting with controls we call “custom buttons” in our apps (among other custom controls).
Welcome to WebIS.net - Pocket Informant iPhone
Pocket Informant for the iPhone doesn't just simply let you view your daily events but lets you really work with them. So many calendar or task applications are either too hard to use or too simple to be useful. Pocket Informant takes eight years of mobile experience and brings a fresh perspective to the iPhone user.
Rails 2.3 Nested Object Forms: I’m not Crazy about Them « SmartLogic Solutions Blog
I just finished reviewing Rails 2.3 Nested Object Forms. While a very nice and “magical” feature, I’ve got to admit that I’m really not that crazy about how it works.
Tagaholic - Console Update With Your Editor
Rails’ script/console makes it easy to fetch, view and edit your database records. But can you edit those records as quickly as you edit code in your text editor? Riiight, like editing our database records in an editor is gonna happen? It already has.
Tagaholic - Hirb - Irb On The Good Stuff
Hirb provides a mini view framework for console applications, designed with irb in mind.