Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Forked from skinnyjames/gist:6055085
Last active December 20, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreapavoni/6062010 to your computer and use it in GitHub Desktop.
Save andreapavoni/6062010 to your computer and use it in GitHub Desktop.
#commit model
class Commit < ActiveRecord::Base
# 1) We don't need a provider based Commit subclass, a String field
# should be enough. In case, we can associate a Provider model
# (1 to 1 relation) that represents a specific provider
# 2) we might want to use commit IDs, then build the commit URL at runtime
# (perhaps an URL template specific to the provider should be specified in Provider model)
# this shuould prevent eventual URL changes by providers :-)
attr_accessible :commit_url, :author, :commit_message, :provider
end
#story model
class Story < ActiveRecord::Base
has_many :notes
has_many :commits
end
#view
# I'd split notes and commits because they should be two separate contexts
# In case, we can merge them in a unique Array and do a sort by timestamp, so
# they can appear mixed with proper ordering
<% story.notes.each do |note| %>
<%= render partial: :note %>
<% end %>
<% story.commits.each do |commit| %>
<%= render partial: commit.provider %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment