Created
February 20, 2016 18:34
-
-
Save drakmail/ab5373a6da57e96b17eb to your computer and use it in GitHub Desktop.
Revisions
-
drakmail created this gist
Feb 20, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class DrinkHabit < Habit # DB structure # id:integer # title:text # food_amount:integer # drink_time:datetime # type: string end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ class FoodHabit < Habit # DB structure # id:integer # title:text # food_amount:integer # drink_time:datetime # type: string end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ class Habit < ActiveRecord::Base # DB structure # id:integer # title:text # food_amount:integer # drink_time:datetime # type: string belongs_to :user end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ class HabitsController < ApplicationController def update habit = Habit.find(params[:id]) if habit.update habits_params redirect_to habit_path(habit) else render 'show' end end protected def habits_params params.require(:habit).permit(:id, :title, :food_amount, :drink_time) end end This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <%= form_for @habit do |f| %> <%= f.text_field :title %> <%= if @habit.is_a? FoodHabit %> <!-- better to use rendering of partials and helper --> <%= f.text_field :food_amount %> <% end %> <% if @habit.is_a? DrinkHabit %> <%= f.text_field :drink_time %> <% end %> <%= f.submit %> <% end %>