lk | adds links to previous and next bikes on bike edit page and removes

bike#show route
This commit is contained in:
Louis Knapp
2016-07-24 07:53:54 -05:00
parent a517eefd73
commit 692f12d47d
5 changed files with 45 additions and 24 deletions
+6 -10
View File
@@ -7,14 +7,16 @@ class BikesController < ApplicationController
@unsold_bikes = @bikes.select{|bike| bike.date_sold.nil? && bike.purpose == "Sale"}
end
def show; end
def new
@bike = Bike.new
@log_number = Bike.order(:log_number).last.log_number + 1
@previous_bike = Bike.order(:log_number).last
@log_number = @previous_bike.log_number + 1
end
def edit; end
def edit
@next_bike = Bike.where(log_number: @bike.log_number + 1).first
@previous_bike = Bike.where(log_number: @bike.log_number - 1).first
end
def print_select
@bikes = Bike.where.not(purpose: "Freecyclery").order(:log_number).reverse_order.paginate(:page => params[:page], :per_page => 30)
@@ -45,7 +47,6 @@ class BikesController < ApplicationController
end
def update
if @bike.update(bike_params)
redirect_to @bike, notice: 'Bike was successfully updated.'
else
@@ -53,11 +54,6 @@ class BikesController < ApplicationController
end
end
def destroy
@bike.destroy
redirect_to bikes_url
end
def mark_as_sold
current_date = Time.new.strftime("%Y-%m-%d")
@bike = Bike.find(params[:id])
+8 -2
View File
@@ -5,6 +5,12 @@
.col-sm-3.col-sm-offset-3
=button_to "Mark as sold", {action: "mark_as_sold", id: @bike.id}, method: :patch, class: "btn btn-default"
= render 'edit_form'
= link_to 'Show', @bike
- if @next_bike
= link_to 'Next Bike', edit_bike_path(@next_bike)
- else
= link_to 'New Bike', new_bike_path
|
= link_to 'Back', bikes_path
= link_to 'All Bikes', bikes_path
- if @previous_bike
|
= link_to 'Previous Bike', edit_bike_path(@previous_bike)
+3 -1
View File
@@ -1,4 +1,6 @@
.container
%h1 New bike
= render 'new_form'
= link_to 'Back', bikes_path
= link_to 'All Bikes', bikes_path
|
= link_to 'Previous Bike', edit_bike_path(@previous_bike)