Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

class complete

  • Loading branch information...
commit f3da862927dcd7f393ce16b2dda64d300d0697e5 1 parent 88dc831
@kornypoet authored
View
3  app/assets/javascripts/hotels.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/stylesheets/hotels.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the hotels controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
54 app/controllers/hotels_controller.rb
@@ -0,0 +1,54 @@
+class HotelsController < ApplicationController
+
+ before_filter :load_hotel, except: [:new, :index, :create]
+
+ def index
+ @hotels = Hotel.all
+ end
+
+ def show
+ respond_to do |format|
+ format.html
+ format.xml{ render xml: @hotel.to_xml }
+ format.json{ render json: @hotel.to_json }
+ end
+ end
+
+ def new
+ @cities = City.order(:name).all
+ @hotel = Hotel.new
+ end
+
+ def create
+ @hotel = Hotel.new(params[:hotel])
+ if @hotel.save
+ redirect_to @hotel
+ else
+ flash[:error] = @hotel.errors
+ @cities = City.order(:name).all
+ render :new
+ end
+ end
+
+ def edit
+ @cities = City.order(:name)
+ end
+
+ def update
+ if @hotel.update_attributes(params[:hotel])
+ redirect_to @hotel
+ else
+ flash[:error] = @hotel.errors
+ @cities = City.order(:name).all
+ render :new
+ end
+
+ end
+
+private
+
+ def load_hotel
+ @hotel = Hotel.find(params[:id])
+ end
+
+end
View
7 app/helpers/hotels_helper.rb
@@ -0,0 +1,7 @@
+module HotelsHelper
+
+ def day_today
+ Date.today.strftime "%A"
+ end
+
+end
View
7 app/models/city.rb
@@ -0,0 +1,7 @@
+class City < ActiveRecord::Base
+
+ attr_accessible :name
+
+ has_many :hotels
+
+end
View
22 app/models/hotel.rb
@@ -0,0 +1,22 @@
+class Hotel < ActiveRecord::Base
+
+ belongs_to :city
+
+ attr_accessible :name, :description, :city_id
+ validates :name, presence: true, length: { minimum: 2 }
+
+ before_save :ensure_capitalization
+
+ def ensure_capitalization
+ self.name = self.name.titlecase
+ end
+
+ class << self
+
+ def yet_to_visit
+ where(visited: false)
+ end
+
+ end
+
+end
View
3  app/models/trip.rb
@@ -0,0 +1,3 @@
+class Trip < ActiveModel::Base
+
+end
View
12 app/views/hotels/_form.html.erb
@@ -0,0 +1,12 @@
+<%= form_for @hotel do |f| %>
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+ <%= f.label :description %>
+ <%= f.text_area :description %>
+
+ <%= f.label :city %>
+ <%= f.collection_select :city_id, @cities, :id, :name %>
+
+ <%= f.submit :save %>
+<% end %>
View
3  app/views/hotels/edit.html.erb
@@ -0,0 +1,3 @@
+<h1>Edit Hotel<h1>
+
+<%= render partial: 'form' %>
View
8 app/views/hotels/index.html.erb
@@ -0,0 +1,8 @@
+<h1>Hotels as of <%= day_today %></h1>
+
+<p>Here are our hotels:</p>
+<ul>
+ <% @hotels.each do |hotel| %>
+ <li><%= link_to hotel.name, hotel %></li>
+ <% end %>
+</ul>
View
3  app/views/hotels/new.html.erb
@@ -0,0 +1,3 @@
+<h1>Create Hotel</h1>
+
+<%= render partial: 'form' %>
View
7 app/views/hotels/show.html.erb
@@ -0,0 +1,7 @@
+<h1><%= @hotel.name %></h1>
+<div>
+ <u1><%= @hotel.description %></u1>
+ </div>
+<div>
+ <u1><%= @hotel.city.name %></u1>
+</div>
View
6 app/views/layouts/application.html.erb
@@ -8,7 +8,11 @@
</head>
<body>
-<%= yield %>
+ <% if flash[:error] %>
+ <p><%= flash[:error] %></p>
+ <% end %>
+
+ <%= yield %>
</body>
</html>
View
5 config/routes.rb
@@ -1,4 +1,9 @@
LsrcRails::Application.routes.draw do
+
+ resources :hotels
+
+ root to: "hotels#index"
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
13 db/migrate/20120809164840_create_hotels.rb
@@ -0,0 +1,13 @@
+class CreateHotels < ActiveRecord::Migration
+ def up
+ create_table :hotels do |t|
+ t.string :name
+ t.text :description
+ t.timestamps
+ end
+ end
+
+ def down
+ drop_tabel :hotels
+ end
+end
View
9 db/migrate/20120809172236_create_cities.rb
@@ -0,0 +1,9 @@
+class CreateCities < ActiveRecord::Migration
+ def change
+ create_table :cities do |t|
+ t.string :name
+
+ t.timestamps
+ end
+ end
+end
View
5 db/migrate/20120809190622_add_city_reference_to_hotels.rb
@@ -0,0 +1,5 @@
+class AddCityReferenceToHotels < ActiveRecord::Migration
+ def change
+ add_column :hotels, :city_id, :integer
+ end
+end
View
5 db/migrate/20120809192701_add_visited_to_hotels.rb
@@ -0,0 +1,5 @@
+class AddVisitedToHotels < ActiveRecord::Migration
+ def change
+ add_column :hotels, :visited, :boolean
+ end
+end
View
31 db/schema.rb
@@ -0,0 +1,31 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20120809192701) do
+
+ create_table "cities", :force => true do |t|
+ t.string "name"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "hotels", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.integer "city_id"
+ t.boolean "visited"
+ end
+
+end
View
4 db/seeds.rb
@@ -3,5 +3,7 @@
#
# Examples:
#
-# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+#
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
View
241 public/index.html
@@ -1,241 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Ruby on Rails: Welcome aboard</title>
- <style type="text/css" media="screen">
- body {
- margin: 0;
- margin-bottom: 25px;
- padding: 0;
- background-color: #f0f0f0;
- font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
- font-size: 13px;
- color: #333;
- }
-
- h1 {
- font-size: 28px;
- color: #000;
- }
-
- a {color: #03c}
- a:hover {
- background-color: #03c;
- color: white;
- text-decoration: none;
- }
-
-
- #page {
- background-color: #f0f0f0;
- width: 750px;
- margin: 0;
- margin-left: auto;
- margin-right: auto;
- }
-
- #content {
- float: left;
- background-color: white;
- border: 3px solid #aaa;
- border-top: none;
- padding: 25px;
- width: 500px;
- }
-
- #sidebar {
- float: right;
- width: 175px;
- }
-
- #footer {
- clear: both;
- }
-
- #header, #about, #getting-started {
- padding-left: 75px;
- padding-right: 30px;
- }
-
-
- #header {
- background-image: url("assets/rails.png");
- background-repeat: no-repeat;
- background-position: top left;
- height: 64px;
- }
- #header h1, #header h2 {margin: 0}
- #header h2 {
- color: #888;
- font-weight: normal;
- font-size: 16px;
- }
-
-
- #about h3 {
- margin: 0;
- margin-bottom: 10px;
- font-size: 14px;
- }
-
- #about-content {
- background-color: #ffd;
- border: 1px solid #fc0;
- margin-left: -55px;
- margin-right: -10px;
- }
- #about-content table {
- margin-top: 10px;
- margin-bottom: 10px;
- font-size: 11px;
- border-collapse: collapse;
- }
- #about-content td {
- padding: 10px;
- padding-top: 3px;
- padding-bottom: 3px;
- }
- #about-content td.name {color: #555}
- #about-content td.value {color: #000}
-
- #about-content ul {
- padding: 0;
- list-style-type: none;
- }
-
- #about-content.failure {
- background-color: #fcc;
- border: 1px solid #f00;
- }
- #about-content.failure p {
- margin: 0;
- padding: 10px;
- }
-
-
- #getting-started {
- border-top: 1px solid #ccc;
- margin-top: 25px;
- padding-top: 15px;
- }
- #getting-started h1 {
- margin: 0;
- font-size: 20px;
- }
- #getting-started h2 {
- margin: 0;
- font-size: 14px;
- font-weight: normal;
- color: #333;
- margin-bottom: 25px;
- }
- #getting-started ol {
- margin-left: 0;
- padding-left: 0;
- }
- #getting-started li {
- font-size: 18px;
- color: #888;
- margin-bottom: 25px;
- }
- #getting-started li h2 {
- margin: 0;
- font-weight: normal;
- font-size: 18px;
- color: #333;
- }
- #getting-started li p {
- color: #555;
- font-size: 13px;
- }
-
-
- #sidebar ul {
- margin-left: 0;
- padding-left: 0;
- }
- #sidebar ul h3 {
- margin-top: 25px;
- font-size: 16px;
- padding-bottom: 10px;
- border-bottom: 1px solid #ccc;
- }
- #sidebar li {
- list-style-type: none;
- }
- #sidebar ul.links li {
- margin-bottom: 5px;
- }
-
- .filename {
- font-style: italic;
- }
- </style>
- <script type="text/javascript">
- function about() {
- info = document.getElementById('about-content');
- if (window.XMLHttpRequest)
- { xhr = new XMLHttpRequest(); }
- else
- { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
- xhr.open("GET","rails/info/properties",false);
- xhr.send("");
- info.innerHTML = xhr.responseText;
- info.style.display = 'block'
- }
- </script>
- </head>
- <body>
- <div id="page">
- <div id="sidebar">
- <ul id="sidebar-items">
- <li>
- <h3>Browse the documentation</h3>
- <ul class="links">
- <li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
- <li><a href="http://api.rubyonrails.org/">Rails API</a></li>
- <li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
- <li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
- </ul>
- </li>
- </ul>
- </div>
-
- <div id="content">
- <div id="header">
- <h1>Welcome aboard</h1>
- <h2>You&rsquo;re riding Ruby on Rails!</h2>
- </div>
-
- <div id="about">
- <h3><a href="rails/info/properties" onclick="about(); return false">About your application&rsquo;s environment</a></h3>
- <div id="about-content" style="display: none"></div>
- </div>
-
- <div id="getting-started">
- <h1>Getting started</h1>
- <h2>Here&rsquo;s how to get rolling:</h2>
-
- <ol>
- <li>
- <h2>Use <code>rails generate</code> to create your models and controllers</h2>
- <p>To see all available options, run it without parameters.</p>
- </li>
-
- <li>
- <h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
- <p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
- </li>
-
- <li>
- <h2>Create your database</h2>
- <p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
- </li>
- </ol>
- </div>
- </div>
-
- <div id="footer">&nbsp;</div>
- </div>
- </body>
-</html>
View
7 test/fixtures/cities.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
+
+one:
+ name: MyString
+
+two:
+ name: MyString
View
7 test/functional/hotels_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class HotelsControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
7 test/unit/city_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CityTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/hotels_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class HotelsHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.