Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Last active December 27, 2015 17:18
Show Gist options
  • Save laspluviosillas/7360700 to your computer and use it in GitHub Desktop.
Save laspluviosillas/7360700 to your computer and use it in GitHub Desktop.
Interview Question #3
class Author < ActiveRecord::Base
attr_accessible :name, :admin # :name => string, :admin => boolean
has_many :posts
end
class Post < ActiveRecord::Base
attr_accessible :name, :description # :author_id => int, :name => string, :description => string
belongs_to :author
has_many :comments
end
class Comment < ActiveRecord::Base
attr_accessible :description # :post_id => int, :description => string
belongs_to :post
end
# Structure example:
# Author -- name: James Strong, admin: true
# Post -- name: "I like Ruby", description "Ruby on Rails is great!"
# Comment -- description: "This is a good post"
# => Search all the Comments that have an Author (through the Post relationship) that is an administrator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment