Created
December 13, 2011 13:57
-
-
Save seanhandley/1472205 to your computer and use it in GitHub Desktop.
This file contains 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 characters
class QuotesController < ApplicationController | |
def new | |
@quote = Quote.new | |
build_airports | |
end | |
def create | |
quote = Quote.new(params[:quote]) | |
message, redirection_params, @quote = QuoteFlowControl.build(quote, params[:commit]) | |
if quote.save | |
@quote.special_requests.create({ content: params[:requests] }) | |
@quote.notes.create({ content: params[:notes] }) | |
end | |
flash.merge!(message) | |
if @quote.errors.empty? | |
redirect_to redirection_params | |
else | |
build_airports | |
render :action => 'new' | |
end | |
end | |
def edit | |
@quote = Quote.find(params[:id]) | |
@special_requests = @quote.special_requests | |
@notes = @quote.notes | |
build_airports | |
end | |
def update | |
quote = Quote.find(params[:id]) | |
message, redirection_params, @quote = QuoteFlowControl.build(quote, params[:commit], params[:quote]) | |
if params[:requests] | |
@quote.create_special_request(params[:requests]) | |
end | |
if params[:notes] | |
@quote.create_note(params[:notes]) | |
end | |
flash.merge!(message) | |
if quote.errors.empty? | |
redirect_to redirection_params | |
else | |
build_airports | |
render :action => 'edit' | |
end | |
end | |
def show | |
options = params[:force_hotel] ? {force: HotelSearch} : {} | |
@search = SearchFactory.create(Quote.find(params[:id]), options) | |
@results = @search.search.results | |
if params[:commit] == 'Filter' | |
@results = @search.filter( | |
board_basis: params[:board_basis], | |
name: params[:hotel_name], | |
rating: params[:rating] | |
) | |
end | |
@title = 'Search results' | |
if @results.empty? | |
flash[:notice] = "No results found!" | |
end | |
end | |
def find_quote | |
@quote = Quote.find(params[:id]) | |
redirect_to edit_quote_path(@quote.id) | |
rescue ActiveRecord::RecordNotFound | |
flash[:error] = "Quote reference #{params[:id]} does not exist" | |
redirect_to new_quote_path | |
end | |
private | |
def build_airports | |
@departure_airports ||= AirportGroup.menu | |
@airports = Destination.destinations_menu | |
end | |
def options_for_flexibility | |
HolidayDurationPresenter.options_array_for_days(9, "+/- ") | |
end | |
helper_method :options_for_flexibility | |
def options_for_duration | |
HolidayDurationPresenter.options_array_for_nights(28) | |
end | |
helper_method :options_for_duration | |
def calculate_total_flight_price(adults, adult_price, children, children_price) | |
FlightSearchPresenter.calculate_total_flight_price(adults, adult_price, children, children_price) | |
end | |
helper_method :calculate_total_flight_price | |
def format_price_breakdown(adults, adult_price, children, children_price, infants=0) | |
FlightSearchPresenter.format_price_breakdown(adults, adult_price, children, children_price, infants) | |
end | |
helper_method :format_price_breakdown | |
def strip_invalid_chars(input) | |
HotelSearchPresenter.strip_invalid_chars(input) | |
end | |
helper_method :strip_invalid_chars | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment