Skip to content

Instantly share code, notes, and snippets.

@johnkferguson
johnkferguson / rails_log_rotation.md
Created January 12, 2014 19:48
How to configure Rails to rotate your log files

To configure Rails to rotate your log files while in the development and test environments, add the following to your development.rb and test.rb files found within /config/environments/

# Keeps the Last 5 logfiles which are rotated at every 5MB
config.logger = Logger.new("#{Rails.root}/log/#{ENV['RAILS_ENV']}.log", 5, 5242880)

Found on Stack Overflow

class Event
@attributes = [:a, :b, :c, :d]
attr_accessor *@attributes
end
@johnkferguson
johnkferguson / add_rspec_to_rails.
Created April 30, 2013 19:59
How to add Rspec to Rails and remove Test-Unit
Create your new rails application as:
rails new <app_name> -T
Or remove your test directory from your existing application:
rm -rf test/
Make an entry in your Gemfile:
gem ‘rspec-rails’
@johnkferguson
johnkferguson / default_rails_gems.rb
Created April 28, 2013 16:02
A list of suggested gems to use during development and testing in a Rails app.
gem 'dotenv-rails', group: [:development, :test]
gem 'pg'
gem 'puma'
gem 'haml-rails'
group :development do
gem 'spring'
gem 'spring-commands-rspec'
gem 'annotate'
@johnkferguson
johnkferguson / rails_gemset_setup
Created April 23, 2013 21:22
Terminal commands to create a new Rails app and create an application specific rvm gemset for it.
$ mkdir myRails4app
$ cd myRails4app
$ rvm use ruby-2.0.0@myRails4app --ruby-version --create
$ gem install rails --pre
$ rails new .
To skip test-unit on creation and set postgres as the databse, enter the following:
$ rails new . -T --database=postgresql
@johnkferguson
johnkferguson / attr_accessible_seed
Created April 23, 2013 20:02
To make it possible to assign an attribute in the seed file when it isn't specified as attr_accessible in the model.
Model.attr_accessible :normally_inaccessible_attribute
@johnkferguson
johnkferguson / change_fish_shell
Created April 23, 2013 02:34
Change to fish shell
chsh -s $HOME/.local/bin/fish
@johnkferguson
johnkferguson / Rspec-Config-Application-Instructions
Created April 22, 2013 20:17
Rspec configuration for Rails to be placed within config/application.rb.
Taken from Everyday Rails Testing with RSpec, along with accompanying explanation below:
• fixtures: true specifies to generate a fixture for each model (using a Factory Girl factory, instead of an actual fixture)
• view_specs: false says to skip generating view specs. Request specs are used instead to test interface elements.
• helper_specs: false skips generating specs for the helper files Rails generates with each controller. As your comfort level with RSpec improves, consider changing this option to true and testing these files.
• routing_specs: false omits a spec file for your config/routes.rb file. As your application grows, however, and takes on more complex routing, it’s a good idea to incorporate routing specs.
• And finally, g.fixture_replacement :factory_girl tells Rails to generate factories instead of fixtures, and to save them in the spec/factories directory.
# FizzBuzz - The Programmer's Stairway to Heaven
# Define the fizzbuzz method to do the following: 10pts
# Use the modulo % method (divisible by)
# 2 % 2 #=> true
# 1 % 2 #=> false
# If a number is divisible by 3, puts "Fizz".
# If a number is divisible by 5, puts "Buzz".
# If a number is divisible by 3 and 5, puts "FizzBuzz"
# Use if statements 2pts
# Use the && operator 3pts