Skip to content

Commit

Permalink
dynamic home page
Browse files Browse the repository at this point in the history
  • Loading branch information
jtotoole committed Dec 30, 2015
1 parent b0d02f9 commit 1e56995
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
7 changes: 7 additions & 0 deletions learn-rails/app/controllers/visitors_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class VisitorsController < ApplicationController

def new
@owner = Owner.new
end

end
21 changes: 21 additions & 0 deletions learn-rails/app/models/owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Owner

def name
name = 'Some dude'
end

def birthdate
birthdate = Date.new(1990, 12, 22)
end

def countdown
today = Date.today
birthday = Date.new(today.year, birthdate.month, birthdate.day)
if birthday > today
countdown = (birthday - today).to_i
else
countdown = (birthday.next_year - today).to_i
end
end

end
4 changes: 4 additions & 0 deletions learn-rails/app/views/visitors/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h3>Home</h3>
<p>Welcome to the home of <%= @owner.name %>.</p>
<p>I was born on <%= @owner.birthdate %>.</p>
<p>Only <%= @owner.countdown %> days until my birthday!</p>
55 changes: 1 addition & 54 deletions learn-rails/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
Rails.application.routes.draw do
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

# You can have the root of your site routed with "root"
# root 'welcome#index'

# Example of regular route:
# get 'products/:id' => 'catalog#view'

# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products

# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end

# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end

# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable

# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
root to: 'visitors#new'
end

0 comments on commit 1e56995

Please sign in to comment.