This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read about the yield keyword and ruby blocks. | |
# http://allaboutruby.wordpress.com/2006/01/20/ruby-blocks-101/ | |
# http://ruby.about.com/od/beginningruby/a/Block-Parameters-And-Yielding.htm | |
# http://blog.codahale.com/2005/11/24/a-ruby-howto-writing-a-method-that-uses-code-blocks/ | |
# http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/ | |
# Now that you know how the yield method works, try to write your | |
# own version of the each method without using the each method | |
# provided by ruby. As in, try to build my_each using only the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a skeleton for testing models including examples of validations, callbacks, | |
# scopes, instance & class methods, associations, and more. | |
# Pick and choose what you want, as all models don't NEED to be tested at this depth. | |
# | |
# I'm always eager to hear new tips & suggestions as I'm still new to testing, | |
# so if you have any, please share! | |
# | |
# @kyletcarlson | |
# | |
# This skeleton also assumes you're using the following gems: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model file | |
class User < ActiveRecord::Base | |
has_many :books | |
accepts_nested_attributes_for :books, :reject_if => lambda {|book| book[:name].blank? }, :allow_destroy => true | |
end | |
# :reject_if => it passes the whole hash passed from browser with book details into this Proc(lambda) and iterates over each book hash. The book record is not created if the condition given in the lambda block is satisfied. | |
# :allow_destroy => if set to true, then the book record that was passed from browser, while submitting User form, with a key-value pair :_destroy => 1 (or '1' or true or "true") will be destroyed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I struggled with getting a fading flash[:notice] that would work both with standard served pages as well | |
# as ajax requests. I saw a number of posts online but did not have luck with or they seemed too | |
# complicated. This is what I ended up with from experimentation. | |
# Place the following code in application_helper.rb. Note that you need to either change or name your | |
# containers as I have in this code: | |
# application_helper.rb | |
module ApplicationHelper | |
NewerOlder