Louis | Adding mark-as-sold button to bike edit page

This commit is contained in:
Loos
2014-09-20 12:00:17 -05:00
parent 1b6255a20c
commit b8fc1eff42
6 changed files with 41 additions and 19 deletions
+15
View File
@@ -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])