This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
9,318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Railscasts Episode #185: Formtastic Part 2 | ||
|
||
http://railscasts.com/episodes/185 | ||
|
||
Commands | ||
|
||
script/generate nifty_scaffold problem name:string | ||
rake db:migrate | ||
script/generate nifty_scaffold symptom animal_id:integer problem_id:integer --skip-controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
log/*.log | ||
tmp/**/* | ||
*.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Example application for Railscasts episode. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | ||
|
||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
require 'tasks/rails' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class AnimalsController < ApplicationController | ||
def index | ||
@animals = Animal.all | ||
end | ||
|
||
def show | ||
@animal = Animal.find(params[:id]) | ||
end | ||
|
||
def new | ||
@animal = Animal.new | ||
end | ||
|
||
def create | ||
@animal = Animal.new(params[:animal]) | ||
if @animal.save | ||
flash[:notice] = "Successfully created animal." | ||
redirect_to @animal | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@animal = Animal.find(params[:id]) | ||
end | ||
|
||
def update | ||
@animal = Animal.find(params[:id]) | ||
if @animal.update_attributes(params[:animal]) | ||
flash[:notice] = "Successfully updated animal." | ||
redirect_to @animal | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@animal = Animal.find(params[:id]) | ||
@animal.destroy | ||
flash[:notice] = "Successfully destroyed animal." | ||
redirect_to animals_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Filters added to this controller apply to all controllers in the application. | ||
# Likewise, all the methods added will be available for all controllers. | ||
|
||
class ApplicationController < ActionController::Base | ||
helper :all # include all helpers, all the time | ||
protect_from_forgery # See ActionController::RequestForgeryProtection for details | ||
|
||
# Scrub sensitive parameters from your log | ||
# filter_parameter_logging :password | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class CategoriesController < ApplicationController | ||
def index | ||
@categories = Category.all | ||
end | ||
|
||
def show | ||
@category = Category.find(params[:id]) | ||
end | ||
|
||
def new | ||
@category = Category.new | ||
end | ||
|
||
def create | ||
@category = Category.new(params[:category]) | ||
if @category.save | ||
flash[:notice] = "Successfully created category." | ||
redirect_to @category | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@category = Category.find(params[:id]) | ||
end | ||
|
||
def update | ||
@category = Category.find(params[:id]) | ||
if @category.update_attributes(params[:category]) | ||
flash[:notice] = "Successfully updated category." | ||
redirect_to @category | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@category = Category.find(params[:id]) | ||
@category.destroy | ||
flash[:notice] = "Successfully destroyed category." | ||
redirect_to categories_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class ProblemsController < ApplicationController | ||
def index | ||
@problems = Problem.all | ||
end | ||
|
||
def show | ||
@problem = Problem.find(params[:id]) | ||
end | ||
|
||
def new | ||
@problem = Problem.new | ||
end | ||
|
||
def create | ||
@problem = Problem.new(params[:problem]) | ||
if @problem.save | ||
flash[:notice] = "Successfully created problem." | ||
redirect_to @problem | ||
else | ||
render :action => 'new' | ||
end | ||
end | ||
|
||
def edit | ||
@problem = Problem.find(params[:id]) | ||
end | ||
|
||
def update | ||
@problem = Problem.find(params[:id]) | ||
if @problem.update_attributes(params[:problem]) | ||
flash[:notice] = "Successfully updated problem." | ||
redirect_to @problem | ||
else | ||
render :action => 'edit' | ||
end | ||
end | ||
|
||
def destroy | ||
@problem = Problem.find(params[:id]) | ||
@problem.destroy | ||
flash[:notice] = "Successfully destroyed problem." | ||
redirect_to problems_url | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module AnimalsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Methods added to this helper will be available to all templates in the application. | ||
module ApplicationHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module CategoriesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# These helper methods can be called in your template to set variables to be used in the layout | ||
# This module should be included in all views globally, | ||
# to do so you may need to add this line to your ApplicationController | ||
# helper :layout | ||
module LayoutHelper | ||
def title(page_title, show_title = true) | ||
@content_for_title = page_title.to_s | ||
@show_title = show_title | ||
end | ||
|
||
def show_title? | ||
@show_title | ||
end | ||
|
||
def stylesheet(*args) | ||
content_for(:head) { stylesheet_link_tag(*args) } | ||
end | ||
|
||
def javascript(*args) | ||
content_for(:head) { javascript_include_tag(*args) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ProblemsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Animal < ActiveRecord::Base | ||
attr_accessible :name, :category_id, :born_on, :female, :problem_ids | ||
belongs_to :category | ||
has_many :symptoms | ||
has_many :problems, :through => :symptoms | ||
validates_presence_of :name, :born_on | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Category < ActiveRecord::Base | ||
attr_accessible :name, :description | ||
has_many :animals | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Problem < ActiveRecord::Base | ||
attr_accessible :name | ||
has_many :symptoms | ||
has_many :animals, :through => :symptoms | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Symptom < ActiveRecord::Base | ||
attr_accessible :animal_id, :problem_id | ||
belongs_to :animial | ||
belongs_to :problem | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<% semantic_form_for @animal do |f| %> | ||
<%= f.error_messages %> | ||
<% f.inputs do %> | ||
<%= f.input :name, :hint => "Use the owner's name if none is provided" %> | ||
<%= f.input :born_on, :start_year => 1900 %> | ||
<%= f.input :category, :include_blank => false %> | ||
<%= f.input :female, :as => :radio, :label => "Gender", :collection => [["Male", false], ["Female", true]] %> | ||
<%= f.input :problems, :as => :check_boxes, :required => false %> | ||
<% end %> | ||
<%= f.buttons %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% title "Edit Animal" %> | ||
<%= render :partial => 'form' %> | ||
|
||
<p> | ||
<%= link_to "Show", @animal %> | | ||
<%= link_to "View All", animals_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<% title "Animals" %> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Category</th> | ||
<th>Born On</th> | ||
<th>Female</th> | ||
</tr> | ||
<% for animal in @animals %> | ||
<tr> | ||
<td><%=h animal.name %></td> | ||
<td><%=h animal.category_id %></td> | ||
<td><%=h animal.born_on %></td> | ||
<td><%=h animal.female %></td> | ||
<td><%= link_to "Show", animal %></td> | ||
<td><%= link_to "Edit", edit_animal_path(animal) %></td> | ||
<td><%= link_to "Destroy", animal, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<p><%= link_to "New Animal", new_animal_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% title "New Animal" %> | ||
<%= render :partial => 'form' %> | ||
|
||
<p><%= link_to "Back to List", animals_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<% title "Animal" %> | ||
|
||
<p> | ||
<strong>Name:</strong> | ||
<%=h @animal.name %> | ||
</p> | ||
<p> | ||
<strong>Category:</strong> | ||
<%=h @animal.category_id %> | ||
</p> | ||
<p> | ||
<strong>Born On:</strong> | ||
<%=h @animal.born_on %> | ||
</p> | ||
<p> | ||
<strong>Female:</strong> | ||
<%=h @animal.female %> | ||
</p> | ||
|
||
<p> | ||
<%= link_to "Edit", edit_animal_path(@animal) %> | | ||
<%= link_to "Destroy", @animal, :confirm => 'Are you sure?', :method => :delete %> | | ||
<%= link_to "View All", animals_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<% semantic_form_for @category do |f| %> | ||
<%= f.inputs %> | ||
<%= f.buttons %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% title "Edit Category" %> | ||
<%= render :partial => 'form' %> | ||
|
||
<p> | ||
<%= link_to "Show", @category %> | | ||
<%= link_to "View All", categories_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<% title "Categories" %> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Description</th> | ||
</tr> | ||
<% for category in @categories %> | ||
<tr> | ||
<td><%=h category.name %></td> | ||
<td><%=h category.description %></td> | ||
<td><%= link_to "Show", category %></td> | ||
<td><%= link_to "Edit", edit_category_path(category) %></td> | ||
<td><%= link_to "Destroy", category, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<p><%= link_to "New Category", new_category_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% title "New Category" %> | ||
<%= render :partial => 'form' %> | ||
|
||
<p><%= link_to "Back to List", categories_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% title "Category" %> | ||
|
||
<p> | ||
<strong>Name:</strong> | ||
<%=h @category.name %> | ||
</p> | ||
<p> | ||
<strong>Description:</strong> | ||
<%=h @category.description %> | ||
</p> | ||
|
||
<p> | ||
<%= link_to "Edit", edit_category_path(@category) %> | | ||
<%= link_to "Destroy", @category, :confirm => 'Are you sure?', :method => :delete %> | | ||
<%= link_to "View All", categories_path %> | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | ||
<head> | ||
<title><%= h(yield(:title) || "Untitled") %></title> | ||
<%= stylesheet_link_tag 'application', 'formtastic', 'formtastic_changes', :cache => "base" %> | ||
<%= yield(:head) %> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<%- flash.each do |name, msg| -%> | ||
<%= content_tag :div, msg, :id => "flash_#{name}" %> | ||
<%- end -%> | ||
<%- if show_title? -%> | ||
<h1><%=h yield(:title) %></h1> | ||
<%- end -%> | ||
<%= yield %> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% form_for @problem do |f| %> | ||
<%= f.error_messages %> | ||
<p> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</p> | ||
<p><%= f.submit "Submit" %></p> | ||
<% end %> |
Oops, something went wrong.