apidock.com

...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...

makandra dev

...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...

makandra dev
activestate.com

...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...

Since May 2011 we are cutting new gems using Bundler, which is less painful than cutting gems using Jeweler. You know a gem was cut using Bundler if you see...

This is how to update a gem that was cut using Bundler: Say git pull or check out a repository from Github like git clone git@github.com:makandra/geordi.git

...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...

...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...

live.julik.nl

The linked article provides a good overview of the various concurrency primitives in Ruby, and what's changing in Ruby...

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...

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. \

...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...

makandra dev

...methods and properties) video = document.querySelector('video') video.play() video.pause() video.load() // Reset to the beginning and select the best available source video.currentSrc // The selected source video.currentTime // The current playback time (in seconds...

...video.ended // Whether the video has finished video.muted video.paused video.readyState // See comments video.volume Comments controls makes the browser show its own video controls The image given in poster will be shown...

web.archive.org

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...

rubydoc.info

...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...

Capybara will match elements outside of a page's tag. For example, the step definitions below match nodes in a page's : Then /^my browser should auto-discover the "([^"]*)" feed...

page.should have_css( 'head link' + '[rel="alternate"]' + "[href='http://www.example.com/#{slug}/feed.rss']" + '[title="RSS feed (all cards)"]' + '[type="application/rss+xml"]', visible: false ) end Then /^my browser should...

Ruby's String#split returns an array of substrings from the given string. Usually, this is missing the split characters: >> 'user@example.com'.split('@') => ["user", "example.com"] If you want to join those...

...parts later on, you might know the split character and can just use it to join explicitly. But if you split by a regular expression (for a set of split...

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.

...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

pganalyze.com

It's every developer's nightmare: SQL queries that get large and unwieldy. This can happen fairly quickly with the addition of multiple joins, a subquery and some complicated filtering...

...logic. I have personally seen queries grow to nearly one hundred lines long in both the financial services and health industries. Luckily Postgres provides two ways to encapsulate large queries...

...default Ruby, RubyMine will give you incorrect inspections, for example.\ Here is how to switch which Ruby you use in RubyMine. File → Settings (Or press Ctrl+Alt+S)

...SDK and Gems" from the left pane Switch your "Ruby interpreter". Though it may seem you are changing a global setting here, this is in fact a per-project setting...

find . -cnewer other_file This can be used to check against a specific timestamp, too. This is how you check for all files modified today (since...

...the current bash's PID so you will get some file like /tmp/12345 that stays the same for the current shell. This allows you to check against this file again...

Sometimes you want to have a time in a given timezone independent from you Rails timezone settings / system timezone. I usually have this use case in tests. Example

...results e.g. 2020-08-09 00:00:00 +0200 depending on the Rails timezone settings / system timezone. But in this example we always want to have the given time in...