Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added check boxes to the nested models which will make it raise an ex…

…ception. This is so people can easily play with transactions.
  • Loading branch information...
commit ce66710f0e4dc3e071b12e1d0248a41668ab2e6a 1 parent d142946
Eloy Durán authored
9 app/models/author.rb
... ... @@ -1,3 +1,12 @@
1 1 class Author < ActiveRecord::Base
2 2 has_many :projects
  3 +
  4 + attr_accessor :raise_exception
  5 +
  6 + after_save :raise_exception_if_needed
  7 + def raise_exception_if_needed
  8 + if @raise_exception.to_i == 1
  9 + raise 'Oh noes!'
  10 + end
  11 + end
3 12 end
9 app/models/tag.rb
... ... @@ -1,3 +1,12 @@
1 1 class Tag < ActiveRecord::Base
2 2 validates_presence_of :name, :message => "can't just be blank"
  3 +
  4 + attr_accessor :raise_exception
  5 +
  6 + after_save :raise_exception_if_needed
  7 + def raise_exception_if_needed
  8 + if @raise_exception.to_i == 1
  9 + raise 'Oh noes!'
  10 + end
  11 + end
3 12 end
9 app/models/task.rb
... ... @@ -1,4 +1,13 @@
1 1 class Task < ActiveRecord::Base
2 2 belongs_to :project
3 3 validates_presence_of :name
  4 +
  5 + attr_accessor :raise_exception
  6 +
  7 + after_save :raise_exception_if_needed
  8 + def raise_exception_if_needed
  9 + if @raise_exception.to_i == 1
  10 + raise 'Oh noes!'
  11 + end
  12 + end
4 13 end
10 app/views/projects/_form.html.erb
@@ -13,6 +13,9 @@
13 13 <% project_form.fields_for :author do |author_form| %>
14 14 <%= author_form.label :name, "Author name:" %>
15 15 <%= author_form.text_field :name %>
  16 +
  17 + <%= author_form.label :raise_exception, "Raise exception:" %>
  18 + <%= author_form.check_box :raise_exception %>
16 19 <% end %>
17 20 </p>
18 21
@@ -22,6 +25,10 @@
22 25 <p>
23 26 <%= task_form.label :name, "Task:" %>
24 27 <%= task_form.text_field :name %>
  28 +
  29 + <%= task_form.label :raise_exception, "Raise exception:" %>
  30 + <%= task_form.check_box :raise_exception %>
  31 +
25 32 <!-- Uses JS to hide this `task' and set a hidden_field with the name
26 33 `_delete' to "1" which causes the record to be deleted. -->
27 34 <%= remove_link_unless_new_record(task_form) %>
@@ -40,6 +47,9 @@
40 47 <%= tag_form.label :name, "Tag:" %>
41 48 <%= tag_form.text_field :name %>
42 49
  50 + <%= tag_form.label :raise_exception, "Raise exception:" %>
  51 + <%= tag_form.check_box :raise_exception %>
  52 +
43 53 <% unless tag_form.object.new_record? %>
44 54 <!-- For existing records we add a checkbox to be able to delete records. -->
45 55 <%= tag_form.label :_delete, "Remove:" %>

0 comments on commit ce66710

Please sign in to comment.
Something went wrong with that request. Please try again.