When you set both a record's association and that association's foreign key attribute, Rails does not realize you are talking about the same thing. The association change will...
...win in the next save, even if the foreign key attribute was changed after the association. As an example, assume you have these two models: class Group < ActiveRecord::Base
Current webkit browsers like Chrome and Safari have a special variable in their consoles that refers to the selected DOM node in the elements panel. This lets us easily inspect...
...Angular scopes. Right click in the page and click "Inspect" to open the Dev Tools Select the element you're interested in from the elements panel Focus the console (in...
fake_stripe spins up a local server that acts like Stripe’s and also serves a fake version of Stripe.js, Stripe’s JavaScript library that allows you to collect your...
...customers’ payment information without ever having it touch your servers. It spins up when you run your feature specs, so that you can test your purchase flow without hitting Stripe...
...needed a way to make my apps full screen from bash scripts. There is no super-easy way, but it's not too hard either. Put the attached script into...
...e.g. /usr/local/bin and make it executable. Now you can call fullscreen Safari and Safari will go full screen. Notes This script needs activated access for assisting devices. Turn it on...
When dealing with external data sources, you may have to deal with improperly encoded strings. While you should prefer deciding on a single encoding with the data-providing party, you...
...can not always force that on external sources. It gets worse when you receive data with encoding declaration that does not reliably fit the accompanying string bytes.
...can be especially painful when external code (read: gems) uses const_defined? to look something up and gets different results on different Rubies. Consider this: module Foo FOO = 42
end On Ruby 1.8, Bar won't have FOO defined as a constant since that's (even though it's accessible): 1.8.7 > Foo.const_defined? :FOO => true 1.8.7 > Bar.const_defined...
...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:create_symlink. I also suggest to put a safeguard into your deploy.rb that...
...and a damaged reputation. Deploy Ruby with confidence knowing you're using the most secure, enterprise-grade builds for the platforms that power your business. You'll get priority access...
...fail-safe Ruby for business applications, but don't require advanced features like indemnification or site-wide licensing. Business Edition customers trust ActiveState's guaranteed technical support and regular fixes...
...association. For example you can put the blank form on top with the following snippet: actors = movie.actors actors.build actors.unshift(actors.pop(1)) # won't work with Rails 4+ Because build_for...
...one-to-many association collection object you only have to reorder the collection objects. Sorting with Rails 3+ = form.fields_for :children, @parent.children.sort_by(&:name) do |fieldsform...
track down warnings and to see failing specs immediately or to get an overview of the core functionalities, you can use RSpec's "nested" format. It looks...
Tool validations should require model to be set should require place_id to be set #identifier should include the model and tag if the tool has a tag...
...OPTS="--no-tcmalloc" rbenv install, but that would disable tcmalloc. Doing that, you might still encounter issues with ossl_ssl.c -- which is where I switched to the patched solution above...
...without_callbacks. There is no such thing in vanilla Rails 3. There is a gem sneaky-save that restores the missing functionality with a #sneaky_save method...
String#indent is not a standard Ruby method. When you use it, be sure to know where this method comes from. Many Gems shamelessly define this method for internal usage...
...and you'll never know when it may be removed (since it's usually not part of the Gem's API). Unless you're using Rails 4 (which brings String...
...both column name and value are coming from user input and need to be sanitized. Unfortunately this works in SQLite but does not in MySQL: named_scope :filter, lambda { |attribute...
{ :conditions => [ 'articles.? = ?', attribute, value ] } } The solution is to use sanitize_sql_array like this: named_scope :filter, lambda { |attribute, value| { :conditions => sanitize_sql_array([ "`articles`.`%s` = '%s'", attribute, value...
...it's likely that your cucumber.yml is just fine but not your rerun.txt.\ This sometimes happens when running multiple Cucumber workers with parallel_tests that write into rerun.txt simultaneously -- ending...
...Just remove it and you are good to go again: rm rerun.txt Another possible solution is to have one rerun file per worker for which you'd need to modify...
There are several ways to merge two (or more) PDF files to a single file using the Linux command line. If you're looking for graphical tools to edit or...
...annotate a PDF, we have a separate card for that. PDFtk (recommended) PDFtk is a great toolkit for manipulating PDF documents. You may need to install it first (sudo apt...
...context) is run outside of transactions, so data created here will bleed into other specs before(:example) is run before each spec inside it, Generally, you'll want a clean...
...setup for each spec so that they are independent of other specs in the same context. Example Consider this spec: describe User, 'something' do before :context do @user = User.make
Back in the old days, we couldn't do something like that: .foo { position: absolute; bottom: 0; /* This was bad: */ left: 10px; right: 10px; } Why? Because IE5 and IE6 (which...
...then) failed horribly trying to render it. I've now checked if this is still an issue with any browser that's not from the stone age. \
Ubuntu has a package mysql-sandbox that lets you install multiple MySQL versions into your user home: Install mysql-sandbox sudo apt install mysql-sandbox Download the version of MySQL...
...you want to use from mysql.com: https://dev.mysql.com/downloads/file/?id=480427 Make sure to choose "Generic Linux" instead of "Ubuntu" so you get a .tar.gz instead of .deb cd into the directory...
...because a printer's resolution is usually much higher than that of a computer screen. If an image absolutely must look awesome when printed, a solution is to embed the...
...image in much higher solution than needed (e.g. four times the horizontal resolution), then scale it down to the desired width using CSS. Note that this will slightly alter the...
...run our end-to-end tests with headless Chrome. While it's a very stable solution overall, we sometimes see the headless Chrome process freeze (or the Capybara driver losing...
...connection, we're not sure). The effect is that your test suite suddenly stops progressing without an error. You will eventually see an error after a long timeout but until...
Restricting access to cookies is essential for security in many web apps. For example, the session ID, the secret token used to identify a particular session, is typically stored in...
...a cookie. Cookies have several important settings. Previously, I discussed the secure flag. This time, let’s dive into the cookie domain. The cookie domain is an important security feature...
...variations' was not found; perhaps you misspelled it? I just was hunting down a strange error with this model: class Model placeholder = 'variations' has_many placeholder nested_scope :verbose, :include...
...work (the latter returned [ :some_association, 'variations' ]). Eventually, the quotes led me to the solution: I had to write has_many placeholder.to_sym. When Rails can't find an association...
...hard to achieve), because it is no actual "integration testing". If you use this step, know what you are doing. Destroying a record with Capybara is not as easy as...
...user, method: :delete), because RackTest's visit can only perform GET requests. With this step you can destroy a records using either Selenium or RackTest. Example: When I destroy that...