Skip to content

Instantly share code, notes, and snippets.

View DCarper's full-sized avatar

Dan Carper DCarper

View GitHub Profile
- owner_only do
= link_to "My Control Panel", edit_bracket_path(@bracket), :title => 'My Control Panel'
Spec::Runner.configure do |config|
config.mock_with :mocha
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
Scenario: I should see a max of 5 comments
Given there are 6 comments
When /^I delete that comment$/ do
@comment = Comment.last
debugger
When %Q{I press "X" within "#comments li:first .destroy_comment"}
end
if defined?(ActiveRecord::Base)
begin
require 'database_cleaner'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.clean
rescue LoadError => ignore_if_database_cleaner_not_present
end
end
$(function() {
$('#comments li').highlightDeleteButton(); // delete button goes red on hover
})
$.fn.highlightDeleteButton = function() {
var $delete_button = $(this).find('input[type=submit]');
$(this).live('hover', function() {
$delete_button.toggleClass('serious')})
}
$.fn.highlightDeleteButton = function() {
$(this).live('hover', function() {
this.delete_button = this.delete_button || $(this).find('input[type=submit]');
this.delete_button.toggleClass('serious');
})
}
# i need the 5 most recent guesses
# option1 - scope on guesses
@bracket.guesses.most_recent(5)
# option2 - relationship that overlaps with bracket has_many :guesses
@bracket.five_most_recent_guesses
#option3 - an explicit method on the bracket instance
@bracket.five_most_recent_guesses which just runs it's own hard coded query
class Album < ActiveRecord::Base
attr_accessible :title
has_one :artist , :dependent => :destroy
has_many :genres , :dependent => :destroy
accepts_nested_attributes_for :artist, :allow_destroy => true
end
def index
@comments = ....
respond_to do |wants|
wants.json { render :json => { :comments => render_to_string(:partial => 'comments/comments_box.html.haml', :locals => { :comments => @comments}) }.to_json }
end
end