ActionView::Template::Error (dump format error for symbol(0x6d))
I recently encountered the error above when I was running selenium tests.
Thanks to a post on stackoverflow I found out that clearing all files in tmp/cache in my project folder made the issue go away.
Switch to a recently opened tab with Cucumber
Similar to closing an opened browser window, spreewald now supports the I switch to the new browser tab
step.
Info
See the Spreewald README for more cool features.
You can use it to test links that were opened with a link_to(..., :target => '_blank')
link or other ways that create new tabs or windows.
Important
This only works with
Selenium
...
iOS 5 "position: fixed" and virtual keyboard issues
The ipad onscreen keyboard changes position:fixed
style to position:static
that misplaces those elements and you'll have problems on each page with a form, e.g. search field.
There are several workarounds/hacks but no straight forward fix yet. Expect additional expense.
Batch-process text files with ruby
Did you know you can do in-place batch processing with plain ruby?
The following script will in-place replace "foo" with "bar" in all files you feed it. Call it with ./my_script path/to/my/files/*
#!ruby -i -p
$_.gsub!(/foo/, "bar")
"'-i -p" means:
Ruby will run your script once for each line in each file. The line will be placed in $_
. The value of $_
at the end of your script will be written back to the file.
Shorter
Using the Kernel#gsub
shorthand for $_.gsub!
:
#!ruby -i -p
gsub(/foo/, "bar")
S...
List keys stored in memcached / Amazon AWS ElastiCache server
Connect to your memcached host. (AWS elasticache is memcached)
telnet foohost23.cs2631.0001.euw1.cache.amazonaws.com 11211
Once you're connected, find out which 'slabs' exist within the cache:
stats items
STAT items:1:number 3550
STAT items:1:age 5166393
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 0
STAT items:2:number 144886
STAT items:2:age 1375536
STAT items:2:evicted 0
...
Howto remove the location hash without causing the page to scroll
Set the hash to a dummy hash which doesn't hit any id
at your page, for example:
window.location.hash = "_";
Note
- If you'd set the hash to
""
it causes the page to scroll to the top because the hash"#"
by itself is equivalent to"_top"
. - If you'd set
window.location.href = "..."
to get rid of the "#", you cause the browser to reload the page what is most likely not intended.
How to inspect XML files in a terminal
You can use xmllint
to pretty-print ugly XML files on your terminal. Just say:
xmllint --format file.xml
That will restructure containers nicely into individual sections with proper indentation.\
Note that it will automagically work on gzipped XML files!
To write pretty output to a new file, just use the -o
switch (short for --output
):
xmllint --format file.xml -o pretty_file.xml
See the xmllint man page for other useful switches and more information.
How I Explained REST to my Wife
A great and enjoyable introduction into the concept of the web and about what HTTP was designed for. The original post has been removed for some stupid gender discussion.
Riding Rails: Rails 4.0: Final version released!
Rails 4.0 is finally ready after a thorough process of betas and release candidates. It's an amazing new version packed with new goodies and farewells to old features past their expiration date.
Upgrading Rails 2 from 2.3.8 through 2.3.18 to Rails LTS
This card shows how to upgrade a Rails 2 application from Rails 2.3.8 through every single patch level up to 2.3.18, and then, hopefully, Rails LTS.
2.3.8 to 2.3.9
This release has many minor changes and fixes to prepare your application for Rails 3.
Step-by-step upgrade instructions:
- Upgrade
rails
gem - Change your
environment.rb
so it saysRAILS_GEM_VERSION = '2.3.9'
- Change your ...
ActiveRecord.select
Active Record's select method allows you to make use of the power of MySQL select statements. On the one hand it allows you to select specific fields.
Post.select("content")
results in the following query:
"SELECT content FROM `posts`"
This means that your models will be initialized with only the content attribute and you will not be able to access any other attribute. In fact trying so would raise an ActiveRecord::MissingAttributeError error.
Post.select("content").first.title # => ActiveRecord::MissingAttributeErr...
Help me, there is a zombie process!
Here is a good explanation for zombie processes.
Quote:
If you have zombie processes it means those zombies have not been waited for by their parent (look at PPID displayed by ps -l).
You have three choices: Fix the parent process (make it wait); kill the parent; or live with it.
Remember that living with it is not so hard because zombies take up little more than one extra line in the output of ps.
On a server I want to get informed if there are zombie processes and track them wi...
asciidisco/Backbone.Mutators · GitHub
Backbone plugin to override getters and setters with logic.
Rails: Have different session secrets for all environments
The Rails secret_token
must be unique for each application and any instance of it. If not, someone could exploit this by creating a user with ID = 1 (e.g. on staging), sign in and then use that cookie to authenticate on another site (e.g. on production, where the user with ID = 1 probably is the admin).
Here is a one-for-all solution that does not affect current production users, leaving the production token unchanged: prefix the existing secret_token
with #{Rails.env unless Rails.env.production?}
.
Note: There may be tokens in ...
Rails: Send links in emails with the right protocol
ActionMailer per default uses http
as protocol, which enables SSL-stripping. When a logged-in user follows an http
link to your application, it sends the cookies along with it. Although the application redirects the user to https
and from that point has a secure connection to the user, an attacker may overhear that first unsafe request and hijack your session.
Teach ActionMailer to use the right protocol
If your application is behind SSL, turn on using https
application-wide. In your environment file (either global or per environ...
git: How to always pull with rebase
In order to have more human readable git branches, do
git pull --rebase
To always pull like this, write these lines to your ~/.gitconfig:
[pull]
rebase = true
..or use this oneliner
git config --global pull.rebase true
Note that this will break if you pull from other upstream branches like
git pull origin other-branch
If you keep rebasing by default, you can get "merge pulls" like this:
git pull --no-rebase origin other-branch
Pimp my IRB
Put the attached files into your home directory and enjoy.
.irbrc
- defines
interesting_methods
, which is essentially all methods without top-level methods inherited from Object/Module - requires
awesome_print
, if present - requires
interactive_editor
, if present (basically makes vim available) - loads .irbrc_rails if in Rails (e.g. for the Rails console)
.irbrc_rails
- defines
efind(email)
, which is a shortcut to find users by email
...
Virtus: Coercing boolean attributes
TLDR
Do it like this:
attribute :active, Virtus::Attribute::Boolean
Long story
In Virtus you define attribute with their type like this:
attribute :name, String
attribute :birthday, Date
When defining a boolean attributes, you will probably write it like this:
attribute :active, Boolean
The problem is, there is not actually a Boolean
class in Ruby (there's only TrueClass
and FalseClass
), so use Virtus::Attribute::Boolean
instead.
The reason whil...
Bundle capistrano
Capistrano recently had some API changes that can results in deploys not working when running with old deploy.rb
files.
So let's bundle it. Put capistrano into your Gemfile, like this:
# Gemfile
group :deploy do
gem 'capistrano'
gem 'capistrano_colors'
end
It's possible you need to do a bundle update net-ssh
to get things running.
Now double check that all your custom hooks are actually still called. One candidate might be an after deploy:symlink
hook that has been renamed into `after deploy:creat...
Ubuntu: Restart sound services
Sometimes sound breaks for me and speaker output is completely broken. This helped:
pulseaudio -k && sudo alsa force-reload
marcandre/backports · GitHub
Essential backports that enable many of the nice features of Ruby 1.8.7 up to 2.0.0 for earlier versions.
Subscribe to Rails security mailing list without Google account
The Ruby on Rails security list archive can be found here: http://groups.google.com/group/rubyonrails-security
You can subscribe to this mailing list without a Google account by pasting this URL into your browser (after replacing the email address obviously).
http://groups.google.com/group/rubyonrails-security/boxsubscribe?email=your.name@example.com
^^^^^^^^^^^^^^^^^^^^^ <- Change this
Clean up application servers when deploying
Our development process makes us deploy very often. As the number of releases grows, junk clogs up the hard drive of our application servers:
- Old release code
- Old
tmp
folders with compiled view templates etc. - Precompiled assets (Javascripts, images...) that no longer exist. When using the asset pipeline, Capistrano will symlink the
public/assets
directory toshared/assets
. This is cool since we can still serve previous assets after a new release, in the window where browser caches might still have references to old assets. But i...