diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index b131018..787b50a 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -18,30 +18,24 @@ class BikesController < ApplicationController def create @bike = Bike.new(bike_params) - respond_to do |format| - if @bike.save - format.html { redirect_to @bike, notice: 'Bike was successfully created.' } - else - format.html { render action: 'new' } - end + if @bike.save + redirect_to @bike, notice: 'Bike was successfully created.' + else + render action: 'new' end end def update - respond_to do |format| - if @bike.update(bike_params) - format.html { redirect_to @bike, notice: 'Bike was successfully updated.' } - else - format.html { render action: 'edit' } - end + if @bike.update(bike_params) + redirect_to @bike, notice: 'Bike was successfully updated.' + else + render action: 'edit' end end def destroy @bike.destroy - respond_to do |format| - format.html { redirect_to bikes_url } - end + redirect_to bikes_url end private @@ -56,7 +50,6 @@ class BikesController < ApplicationController :model, :bike_type, :color, - :frame_size, :log_number, :purpose, :serial_number, diff --git a/app/models/bike.rb b/app/models/bike.rb index 8d2794d..a03dd34 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -5,4 +5,8 @@ class Bike < ActiveRecord::Base validates :bike_type, presence: true validates :color, presence: true validates :serial_number, presence: true + + def name + [self.seat_tube_size.to_s, self.brand, self.model] * ' ' + end end diff --git a/app/views/clients/_fields.html.haml b/app/views/clients/_fields.html.haml index 7726d4d..e6ed3eb 100644 --- a/app/views/clients/_fields.html.haml +++ b/app/views/clients/_fields.html.haml @@ -50,8 +50,7 @@ = f.text_field :completion_date, class: "form-control datepicker", disabled: disabled .form-group - = f.label "Type:", class: "col-sm-2 control-label" + = f.label "Bike:", class: "col-sm-2 control-label" .col-sm-10 - = f.select(:bike_id, Bike.all.collect {|b| [ b.model, b.id ] }, {include_blank: 'None'}) - + = f.select(:bike_id, Bike.all.collect {|b| [ b.name, b.id ] }, {include_blank: 'None'}) diff --git a/app/views/clients/_form.html.haml b/app/views/clients/_form.html.haml index 41c61fe..b74221e 100644 --- a/app/views/clients/_form.html.haml +++ b/app/views/clients/_form.html.haml @@ -1,12 +1,11 @@ -.container - = form_for @client, html: {class: 'form-horizontal'} do |f| - - if @client.errors.any? - #error_explanation - %h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:" - %ul - - @client.errors.full_messages.each do |msg| - %li= msg - = render 'fields', f: f - .row - .actions.col-sm-offset-2 - = f.submit class: "btn btn-default" += form_for @client, html: {class: 'form-horizontal'} do |f| + - if @client.errors.any? + #error_explanation + %h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:" + %ul + - @client.errors.full_messages.each do |msg| + %li= msg + = render 'fields', f: f + .row + .actions.col-sm-offset-2 + = f.submit class: "btn btn-default" diff --git a/app/views/clients/new.html.haml b/app/views/clients/new.html.haml index 0197754..12241ff 100644 --- a/app/views/clients/new.html.haml +++ b/app/views/clients/new.html.haml @@ -1,3 +1,4 @@ -%h1 New Client -= render 'form' -= link_to 'Back', clients_path +.container + %h1 New Client + = render 'form' + = link_to 'Back', clients_path diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fd2a176..2efcf43 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,10 +1,10 @@ <%= render "layouts/head" %> -<%= render "layouts/navbar" %> - -

<%= notice %>

-

<%= alert %>

- <%= yield %> - + + <%= render "layouts/navbar" %> +

<%= notice %>

+

<%= alert %>

+ <%= yield %> +