summaryrefslogtreecommitdiff
path: root/_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown
diff options
context:
space:
mode:
authorJosé Mota <josemota.net@gmail.com>2012-10-22 12:20:29 +0100
committerJosé Mota <josemota.net@gmail.com>2012-10-22 12:20:29 +0100
commit606a507fff5fc179764b8a0f5d26bc33334ebd86 (patch)
tree69440296d9057949d6e6375a512ffcc47d4afd9c /_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown
parent846d4717600db857de8c254e96d4cf337827afae (diff)
Remove UFZvalidator post and convert other two to markdown.
Diffstat (limited to '_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown')
-rw-r--r--_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown45
1 files changed, 45 insertions, 0 deletions
diff --git a/_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown b/_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown
new file mode 100644
index 0000000..dd00f6b
--- /dev/null
+++ b/_posts/2010-11-05-rails-3-has_many-through-checkboxes.markdown
@@ -0,0 +1,45 @@
+---
+layout: post
+title: ! "Rails 3 has_many :through checkboxes"
+tags: [ development ]
+status: publish
+type: post
+published: true
+---
+
+On Twitter I wrote:
+
+> Rails does it for you, just add sheet_ids[] to the form with the checkboxes and
+> it's done! will blog.
+
+Being a music teacher, my fiance needed to keep record of tests her students
+perform. Also, each test has several sheets that need mentoring and
+monitorization through several parameters. I decided to help and reentered the
+Rails world, and since I have found no answer on this topic, I decided to write
+it myself.
+
+This situation is a perfect model for using the so well known <a
+href="http://railscasts.com/episodes/17-habtm-checkboxes">HABTM checkboxes</a>.
+
+### A closer look at the problem
+
+#### Models
+
+<script src="http://gist.github.com/663287.js"></script>
+
+A pretty basic setup. The <em>venues</em> (the students' tests) include several
+<em>sheets</em> for them to study and for the teacher to evaluate,
+through <em>exhibitions</em> that have several criteria.
+
+#### View
+
+<script src="http://gist.github.com/663417.js"></script>
+
+I simplified the form just so you see what's at stake. The same principle of
+the HABTM checkboxes applies to a has_many :through association. Instead of new
+entries in a venues_sheets table, new <em>Exhibitions</em> are created with the
+respective foreign ids in them.
+
+The controller needs no mention because it stays the same. It just saves /
+updates the model. This is why I love Rails: the hard work is done: you just
+need to focus on what matters.