$ 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') |
| # config/initializers/clear_logs.rb | |
| # This snippet simply clears your logs when they are too large. | |
| # Large logs mean looooong search in TextMate. You know it :) | |
| # Every time you run rails server or rails console it checks log sizes | |
| # and clears the logs for you if necessary. | |
| if Rails.env.development? | |
| MAX_LOG_SIZE = 2.megabytes | |
| class FacebookCommentNotifer | |
| def initialize(comment) | |
| @comment = comment | |
| end | |
| def save | |
| @comment.save && post_to_wall | |
| end | |
| private |
| alias a='ack' | |
| alias a?='alias | grep -i' | |
| alias adx='rake db:drop && rake db:create && heroku pg:transfer --from black --to postgres://postgres@localhost/staq_development --confirm staqweb --app staqweb && rails r "User.all.each { |u| u.update_attribute(:password,%q(password)) }" && rake db:test:prepare' | |
| alias b='bundle' | |
| alias bb='bundle install --binstubs=.bundle/bin --path=.bundle/gems && bundle package --all && reload ; sd' | |
| alias bc='bin/console' | |
| alias be='bundle exec' | |
| alias bea='bundle exec annotate' | |
| alias bu='bundle update' | |
| alias bus='bundle update staq_extraction' |
About once a year, my machine gets pretty sluggish and it's time to start fresh. Here's the process I use to update it with everything I need.
TODO: Add info about dotfiles set up and zsh (possible settings file?)
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb - load your rails into a pry sessionDebugger
| require 'rails_helper' | |
| RSpec.describe TodosController, :type => :controller do | |
| describe "GET #index" do | |
| #describe "POST #create" do | |
| #describe "GET #show" do | |
| #describe "PATCH #update" do (or PUT #update) | |
| #describe "DELETE #destroy" do | |
| #describe "GET #new" do |
| namespace :json do | |
| desc "Export all data to JSON files" | |
| task :export => :environment do | |
| Rails.application.eager_load! | |
| ActiveRecord::Base.descendants.each do |model| | |
| file = File.open(File.join(Rails.root, "db", "export", "#{model.table_name}.json"), 'w') | |
| file.write model.all.to_json | |
| file.close | |
| end |