mirror of
https://github.com/fspc/bike-database.git
synced 2026-09-16 08:31:39 -04:00
Louis | Adding mark-as-sold button to bike edit page
This commit is contained in:
@@ -4,6 +4,10 @@ class BikesController < ApplicationController
|
||||
|
||||
def index
|
||||
@bikes = Bike.all
|
||||
@unsold_bikes = @bikes.select{|bike|
|
||||
!bike.date_sold &&
|
||||
(bike.purpose == "Sale")
|
||||
}
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -47,6 +51,17 @@ class BikesController < ApplicationController
|
||||
redirect_to bikes_url
|
||||
end
|
||||
|
||||
def mark_as_sold
|
||||
current_date = Time.new.strftime("%Y-%m-%d")
|
||||
@bike = Bike.find(params[:id])
|
||||
if @bike.update_attribute(:date_sold, current_date)
|
||||
redirect_to bikes_url, notice: @bike.name + ' was marked as sold on ' + current_date + '.'
|
||||
else
|
||||
render action: edit, notice: 'Bike sale date could not be updated'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_bike
|
||||
@bike = Bike.find(params[:id])
|
||||
|
||||
Reference in New Issue
Block a user