Skip to content

Instantly share code, notes, and snippets.

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

@ivansjg
ivansjg / gist:5335372
Last active December 15, 2015 22:49
init.d script to launch Play framework under Ubuntu
#!/bin/sh
### BEGIN INIT INFO
## END INIT INFO
# Path to play install folder
PLAY_HOME=/path/to/play_home
PLAY=$PLAY_HOME/play
# Path to the JVM
JAVA_HOME=/usr/lib/jvm/java-6-sun
@ivansjg
ivansjg / gist:5335124
Last active December 15, 2015 22:48 — forked from THemming/gist:2173037
init.d script to launch Play framework under CentOS/RedHat
#!/bin/bash
# chkconfig: 345 20 80
# description: Play start/shutdown script
# processname: play
#
# Instalation:
# copy file to /etc/init.d
# chmod +x /etc/init.d/play
# chkconfig --add /etc/init.d/play
# chkconfig play on
@ivansjg
ivansjg / addUser
Last active December 12, 2015 09:39 — forked from wataru420/addUser
Install Jenkins
/usr/sbin/groupadd -g 30119 jenkins
/usr/sbin/useradd -u 30119 -g jenkins jenkins
mkdir /home/jenkins
# Download Play! to /home/jenkins
chown -R jenkins. /home/jenkins
package controllers
import play.api._
import play.api.mvc._
import java.io.File
import java.io.FileInputStream
import play.api.libs.iteratee.Enumerator
object VideoStream extends Controller {