Simply use OpenStruct#to_h to receive an OpenStruct's hash representation. In older Rubies you need OpenStruct#marshal_dump instead. Ruby 2.0+ >> OpenStruct.new(foo: 23, bar: 42).to_h...
...table, MySQL needs to know which table you want to delete from. Let's say that Post belongs_to :author. In order to delete all posts from the author named...
...handling file uploads in Rails. It handles direct uploads (also direct uploads to Amazon S3) better than Carrierwave. The story and reasoning behind some of the decisions in Refile, and...
...a good read before deciding which way you'll go. Big Caveat: Refile only stores the original image and renders the desired version (e.g. smaller, cropped) on page load. This...
...31m\]$(__git_ps1 "(%s)") \[\033[01;34m\]$\[\033[00m\] ' Reload the changes by saying source ~/.bashrc For some customized prompts that also show the current Git prompt, see the examples...
...section at the bottom of our bash prompt customizing card...
Copy the .vdi drive data into the new machine folder In the machine settings, add that .vdi as a hard drive, and remove the dummy .vdi you created when...
...and illformed requirements, it is most probably an error resulting from the transition from Syck to psych. To fix this: go to your gemspec directory (e.g. /Library/Ruby/Gems/1.8/specifications/) change # to = (equals...
...sign) in each file that's complaining
In a Rails application, *_spec.rb files get special treatment depending on the file's directory. E.g. when you put a spec in spec/controllers your examples will have some magic context...
...get that appears out of nowhere. If you want that magic context for a spec in another folder, use the :type option: describe CakesController, :type => :controller do ...
...Rails (e.g. for the Rails console) .irbrc_rails defines efind(email), which is a shortcut to find users by email requires hirb, if present set the prompt to your Rails...
Chart.js seems to be a good alternative to Google's Chart API and other commercial chart drawing libraries. good looking charts canvas based (means less memory consumptive, but no interactivity...
highly configurable good API and documentation just 4.5 kilobytes MIT license Browser support: all browsers supporting the canvas element (for IE8 and below, use the polyfill as describes...
...you ever opened a file with vim, edited it and when you wanted to save your changes it told you "Can't open file for writing", because you opened it...
...without sudo? There's an easy hack to let you write it anyway: :w !sudo tee % The linked SO post explains in detail what will happen. Create a shortcut
Ubuntu lets you mount an SSH shell into Nautilus from Places -> Connect to server (select "SSH" as server type). In order to copy a file over SSH from a shell...
...scp filename username@remotehost: The trailing ":" directs the file to username's home directory on the remote host. You can also copy a file from the remote host to your...
The following Sass will do the trick: button, input[type="reset"], input[type="button"], input[type="submit"], input[type="file"] > input[type="button"] &::-moz-focus-inner border: none
...the with_routing helper -- but that one destroys existing routes which may break a specs that require them to work. To keep both "regular" and test routes, do this:
...MyApplicationController < ActionController::Base def show render text: 'Welcome to my application' end end test_routes = Proc.new do get '/my_application' => 'my_application#show' end Rails.application.routes.eval_block(test_routes)
With its you can switch the subject of an example to a method value of the current subject: describe Array do its(:length) { should == 0 } end stub_chain is the...
...tie to go along with should_receive_chain's tux: object.stub_chain(:first, :second, :third).and_return(:this) You can restore the original implementation of stubbed methods with unstub:
...false, you need to do it like this: nil.should == false # fails as expected Wat? See also RSpec: be_true does not actually check if a value is true
...the data to /tmp/geodb_coodinates.csv. And it's fast: Query OK, 337925 rows affected (0.86 sec) SELECT * INTO OUTFILE '/tmp/geodb_coordinates.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n...
...than cluttering controllers with domain logic, they usually represent a failure to apply the Single Responsibility Principle (SRP). “Anything related to what a user does” is not a single responsibility...
...Early on, SRP is easier to apply. ActiveRecord classes handle persistence, associations and not much else. But bit-by-bit, they grow. Objects that are inherently responsible for persistence become...
...from a drive or image in a virtual machine you do not need to setup up a VirtualBox machine. Often QEMU does the job well enough. Install it:
...get install qemu To boot an ISO: qemu-system-x86_64 -cdrom filename.iso If you prepared a USB pen drive and want to test it, run it like this (/dev/sdx...
...you upgrade to the mysql2 gem, you will run into the problem that the server's database.yml (which is usually not under version control) needs to change exactly on deploy...
...can however make your database.yml work for mysql and mysql2 at the same time. Simpy do this production: adapter: <%= defined?(Mysql2) ? 'mysql2' : 'mysql...
Generally, Selenium tests use the browser to interact with the page. If it's unavailable, a timeout error is thrown. Now, consider a scenario like this: @javascript Scenario: Receive...
...When I follow "fancy link" Then I should have an e-mail with the subject "Hello" When the last step in the scenario passes, you are done. Right? Wrong.
Just a quick note that Virtus can coerce (auto-cast) structured values like collections or maps: class Klass include Virtus.model attribute :dimensions, Hash[Symbol => Float] attribute :numbers, Array[Integer]
I have no idea how it's supposed to work (or why the don't have a print CSS), but this works for pages written with Markdown: "Edit" the wiki...
In addition to the {{ myValue }} two-way binding syntax, since Angular 1.3 there's a one-time binding syntax, prefixing the value or expression with ::, e.g. {{ ::myValue }}, {{ ::myValue >= 42 }} and...
...myExpression(value) | someFilter }}. One-time bound expressions get dropped from the list of watchers as soon as they can be resolved. Performance-wise the impact for this small change is...
...original DOM (template element) before AngularJS creates an instance of it and before a scope is created. Use the pre-link function to implement logic that runs when AngularJS has...