Skip to content

Instantly share code, notes, and snippets.

@bradylove
Created December 29, 2011 01:58
Show Gist options
  • Select an option

  • Save bradylove/1531122 to your computer and use it in GitHub Desktop.

Select an option

Save bradylove/1531122 to your computer and use it in GitHub Desktop.
.well
= form_for @recipe do |f|
-if @recipe.errors.any?
.errorExplanation
= pluralize(@recipe.errors.count, "error")
prohibited you from creating the recipe.
%ul
- @recipe.errors.full_messages.each do |msg|
%li
= msg
%fieldset
%legend
= @legend
.clearfix
= f.label :title
.input
= f.text_field :title
.clearfix
= f.label :difficulty
.input
= f.collection_select :difficulty, Recipe::DIFFICULTIES, :to_s, :humanize
.clearfix
= f.label :prep_time
.input
= f.collection_select :prep_time, Recipe::TIMES, :first, :last
.clearfix
= f.label :cook_time
.input
.clearfix
= f.label :ingredients
.input
.clearfix
= f.label :directions
.input
= f.text_area :directions
class Recipe
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paranoia
field :title
field :cook_time, type: Integer
field :prep_time, type: Integer
field :ingredients, type: Hash
field :directions, type: Array
field :estimated_cost, type: Integer
field :difficulty
field :menu # Breakfast Dinner Lunch etc etc
belongs_to :user
belongs_to :food_type
TIMES = { 5 => "5 Minutes",
10 => "10 Minutes",
15 => "15 Minutes" }
DIFFICULTIES = %w{ easy medium hard }
def total_time
cook_time + prep_time
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment