$ rails g model User
belongs_to
has_one
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
https://www.pivotaltracker.com/help/api?version=v3#github_hooks | |
https://www.pivotaltracker.com/help/api?version=v3#scm_post_commit_message_syntax | |
SCM Post-Commit Message Syntax | |
To associate an SCM commit with a specific Tracker story, you must include a special syntax in the commit message to indicate one or more story IDs and (optionally) a state change for the story. Your commit message should have square brackets containing a hash mark followed by the story ID. If a story was not already started (it was in the "not started" state), a commit message will automatically start it. For example, if Scotty uses the following message when committing SCM revision 54321: | |
[#12345677 #12345678] Diverting power from warp drive to torpedoes. | |
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
Originally published in June 2008
When hiring Ruby on Rails programmers, knowing the right questions to ask during an interview was a real challenge for me at first. In 30 minutes or less, it's difficult to get a solid read on a candidate's skill set without looking at code they've previously written. And in the corporate/enterprise world, I often don't have access to their previous work.
To ensure we hired competent ruby developers at my last job, I created a list of 15 ruby questions -- a ruby measuring stick if you will -- to select the cream of the crop that walked through our doors.
Candidates will typically give you a range of responses based on their experience and personality. So it's up to you to decide the correctness of their answer.
# video.rb | |
class Video < ActiveRecord::Base | |
has_many :categorizations | |
has_many :categories, through: :categorizations | |
end | |
# category.rb | |
class Category < ActiveRecord::Base | |
has_many :categorizations | |
has_many :videos, through: :categorizations |
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
-E
: will describe the underlaying queries of the \
commands (cool for learning!)-l
: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)# require 'pry'; binding.pry | |
# Rails Project Template | |
# Run with: | |
# rails new MyApp -T -m http://............. | |
# John Meehan 2015 | |
# Set the ruby version to that of the RVM | |
insert_into_file('Gemfile', "ruby '#{RUBY_VERSION}'\n", :before => /^ *gem 'rails'/, :force => false) | |
# Set the Gemset name based on the Rails app name | |
insert_into_file('Gemfile', "#ruby-gemset=#{@app_name}\n", :before => /^ *gem 'rails'/, :force => false) |
# Build an image | |
docker build -t <image_name> <dockerfile_path> | |
# Run a container | |
docker run -d -p <host_port>:<container_port> --name <container_name> <image_name> | |
PS1: In this sample, I'm mapping ports with option '-p'. For more details, see below. | |
PS2: You can add links among containers using --link <container_name>:<alias> option. | |
# Start a bash session at a running container | |
docker exec -it <nome_container> bash |
# This makes sure Chrome is always up to date in your test suite | |
# On average this adds about 10 seconds to your build suite | |
# Be sure to use Ubuntu 14.04 (Trusty) in the CircleCI's OS setting (Settings > Build Environment) | |
dependencies: | |
pre: | |
- curl -L -o google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
- sudo dpkg -i google-chrome.deb | |
- sudo sed -i 's|HERE/chrome\"|HERE/chrome\" --disable-setuid-sandbox|g' /opt/google/chrome/google-chrome | |
- rm google-chrome.deb |