mirror of
https://github.com/fspc/bike-database.git
synced 2025-03-12 01:23:23 -04:00
Louis | mild refactorings, add name method to bike
This commit is contained in:
parent
277abcb5c0
commit
47980d61b0
@ -18,30 +18,24 @@ class BikesController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@bike = Bike.new(bike_params)
|
@bike = Bike.new(bike_params)
|
||||||
respond_to do |format|
|
if @bike.save
|
||||||
if @bike.save
|
redirect_to @bike, notice: 'Bike was successfully created.'
|
||||||
format.html { redirect_to @bike, notice: 'Bike was successfully created.' }
|
else
|
||||||
else
|
render action: 'new'
|
||||||
format.html { render action: 'new' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
if @bike.update(bike_params)
|
||||||
if @bike.update(bike_params)
|
redirect_to @bike, notice: 'Bike was successfully updated.'
|
||||||
format.html { redirect_to @bike, notice: 'Bike was successfully updated.' }
|
else
|
||||||
else
|
render action: 'edit'
|
||||||
format.html { render action: 'edit' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@bike.destroy
|
@bike.destroy
|
||||||
respond_to do |format|
|
redirect_to bikes_url
|
||||||
format.html { redirect_to bikes_url }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -56,7 +50,6 @@ class BikesController < ApplicationController
|
|||||||
:model,
|
:model,
|
||||||
:bike_type,
|
:bike_type,
|
||||||
:color,
|
:color,
|
||||||
:frame_size,
|
|
||||||
:log_number,
|
:log_number,
|
||||||
:purpose,
|
:purpose,
|
||||||
:serial_number,
|
:serial_number,
|
||||||
|
@ -5,4 +5,8 @@ class Bike < ActiveRecord::Base
|
|||||||
validates :bike_type, presence: true
|
validates :bike_type, presence: true
|
||||||
validates :color, presence: true
|
validates :color, presence: true
|
||||||
validates :serial_number, presence: true
|
validates :serial_number, presence: true
|
||||||
|
|
||||||
|
def name
|
||||||
|
[self.seat_tube_size.to_s, self.brand, self.model] * ' '
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -50,8 +50,7 @@
|
|||||||
= f.text_field :completion_date, class: "form-control datepicker", disabled: disabled
|
= f.text_field :completion_date, class: "form-control datepicker", disabled: disabled
|
||||||
|
|
||||||
.form-group
|
.form-group
|
||||||
= f.label "Type:", class: "col-sm-2 control-label"
|
= f.label "Bike:", class: "col-sm-2 control-label"
|
||||||
.col-sm-10
|
.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'})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
.container
|
= form_for @client, html: {class: 'form-horizontal'} do |f|
|
||||||
= form_for @client, html: {class: 'form-horizontal'} do |f|
|
- if @client.errors.any?
|
||||||
- if @client.errors.any?
|
#error_explanation
|
||||||
#error_explanation
|
%h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:"
|
||||||
%h2= pluralize(@client.errors.count, "error") + " prohibited this bike from being saved:"
|
%ul
|
||||||
%ul
|
- @client.errors.full_messages.each do |msg|
|
||||||
- @client.errors.full_messages.each do |msg|
|
%li= msg
|
||||||
%li= msg
|
= render 'fields', f: f
|
||||||
= render 'fields', f: f
|
.row
|
||||||
.row
|
.actions.col-sm-offset-2
|
||||||
.actions.col-sm-offset-2
|
= f.submit class: "btn btn-default"
|
||||||
= f.submit class: "btn btn-default"
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
%h1 New Client
|
.container
|
||||||
= render 'form'
|
%h1 New Client
|
||||||
= link_to 'Back', clients_path
|
= render 'form'
|
||||||
|
= link_to 'Back', clients_path
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<%= render "layouts/head" %>
|
<%= render "layouts/head" %>
|
||||||
<%= render "layouts/navbar" %>
|
<body>
|
||||||
<body>
|
<%= render "layouts/navbar" %>
|
||||||
<p class="notice"><%= notice %></p>
|
<p class="notice"><%= notice %></p>
|
||||||
<p class="alert"><%= alert %></p>
|
<p class="alert"><%= alert %></p>
|
||||||
<%= yield %>
|
<%= yield %>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user