Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f3da862927
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (43 sloc) 0.955 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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
Something went wrong with that request. Please try again.