Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

Calendar App 1

Setup

  • added a EventTimeValidator to lib. this needed to be updated in the app config file as well so that the autoload path would pick up the changes in the lib dir.
rspec tests on valdidations
1
2
expect(event).to_not be_valid
expect(event.errors[:end_date]).to eq ["must be after start date"]

Git global config github

Uploads

  • we used carrierwave
    • remember to set multipart to true

Extend self

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module A
  class << self
    include A

    def x
      puts 'x'
    end
  end

  def y
    puts 'y'
  end
end

A.x #=> 'x'
A.y #=> 'y'

Method Stubs

  • A method stub is an implementation that returns a pre-determined value. Method stubs can be declared on test doubles or real objects using the same syntax.
E.G.
1
2
3
book.stub(:title) { "The RSpec Book" }
book.stub(:title => "The RSpec Book")
book.stub(:title).and_return("The RSpec Book")

any_instance

  • stub on any instance of a class
    • Use any_instance.stub on a class to tell any instance of that class to return a value (or values) in response to a given message. If no instance receives the message, nothing happens.
1
2
3
4
5
6
7
8
describe "any_instance.stub" do
  it "returns the specified value on any instance of the class" do
    Object.any_instance.stub(:foo).and_return(:return_value)

    o = Object.new
    o.foo.should eq(:return_value)
  end
end

Alias Attribute

  • alias_attribute :value, :url

Chop v. Chomp

  • subtle difference between chop and chomp
1
2
3
4
5
6
7
8
9
10
11
12
13
#chop
"string\r\n".chop   #=> "string"
"string\n\r".chop   #=> "string\n"
"string\n".chop     #=> "string"
"string".chop       #=> "strin"
"x".chop.chop       #=> ""

#chomp
"hello".chomp            #=> "hello"
"hello\n".chomp          #=> "hello"
"hello\r".chomp          #=> "hello"
"hello \n there".chomp   #=> "hello \n there"
"hello".chomp("llo")     #=> "he"

Setting develop as the default

  • git branch --track develop origin/develop

Formtastic

  • collection groups together elements for a select box
    • include blank false

Deploying

  • need to add new deploy instructions to .git/config file

Nano

  • basic text editor that appears to be pre-loaded…

Offsetting an image and a link

  • use padding to offset an image from its link
    • I use this a lot when putting an icon in front of a link
    • see here for more

Deploying to heroku

  • git push staging develop:master

Each with index

E.G.
1
2
3
@something.each_with_index do |thing,index|
  puts index
end

S3

  • used fog to store the carrierwave uploaded images on AWS
  • needed to config heroku with the heroku config:add ENV_VARIABLE=bucket-name -r staging to make it work
  • in carrierwave.rb need to specify the config.fog_host, but this is NOT the right method. It is supposed to be config.asset_host

xip.io

  • Construct your xip.io domain by appending your application’s name to your LAN IP address followed by .xip.io. For example, if your development computer’s LAN IP address is 10.0.1.43, you can visit myapp.dev from another computer on your local network using the URL http://myapp.10.0.1.43.xip.io/. via

Sweepers and caching actions

  • caches_action :index is all that is needed to cache an action via
  • cache_sweeper :event_sweeper is added to the Events controller to trigger the sweeper…
  • Cache sweeping is a mechanism which allows you to get around having a ton of expire_{page,action,fragment} calls in your code. It does this by moving all the work required to expire cached content into an ActionController::Caching::Sweeper subclass. This class is an observer and looks for changes to an object via callbacks, and when a change occurs it expires the caches associated with that object in an around or after filter.
  • Rails Guide
  • also need to turn on config.cache_store = :dalli_store, ENV['MEMCACHE_SERVERS']

  • In the context of ActiveAdmin

    • We weren’t expiring the events index page, but were rather expiring the ActiveAdmin page instead. This solved the problem, but more specifically specifying the controller.

Comments