Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Introduction to ActiveRecord ActiveRecord Architecture

Yang Bo
PLUS
Yang Bo
Courses Plus Student 8,503 Points

how best practicing to extend ActiveRecord in Gem?

if want to extending models & model's relation in gem, such as https://github.com/jackdempsey/acts_as_commentable Is it only create rails plugin? since we have three options to create "library": 1.) gem(bundle to create) 2.) create plugin 3.) create engine

I have review acts_as_commentable, it is a plugin, extend common & commonable in gem, then use it in rails app. Is it best practices?

or any one have some articles recommend to me for learning

2 Answers

Hampton Catlin
STAFF
Hampton Catlin
Treehouse Guest Teacher

Probably the best guide is here: http://guides.rubyonrails.org/plugins.html

Modern AR extensions are both gems and plugins. Plugins that can be wrapped inside a gem. And, I believe with Rails's command..

 rails plugin new my_plugin

It will automatically setup a lot of what you'll need to build the gem! A lot more good info is in that Rails guide I linked to above.

Any idea what you want to build?

Yang Bo
Yang Bo
Courses Plus Student 8,503 Points

thanks so that Do you mean if want to extend ActiveRecord, for best choose(or only one choose), we should create rails plugin. the plugin has dummy as test project, and test project(dummy) is able to used db, it is testable if I create gem(not plugin) as extending, how to testing the gem which has model( inherit ActiveRecord)? just create the db file(sqlite3) to use?

Hampton Catlin
STAFF
Hampton Catlin
Treehouse Guest Teacher

Gems are just a form of packaging. Think of it like zipping up some files and sending it to a friend. Testing is typically not bundled into gems itself, just what's needed in production.

You build a plugin with tests, then package it as a gem for distribution (often only the stuff needed in production, as I mentioned).

Yang Bo
Yang Bo
Courses Plus Student 8,503 Points

yes, make sense. actually any plugin or engine, if want to implement individual functionality, and it can reuse in other app, that can be named gem. many thanks your explanation.