Last active
August 29, 2015 14:02
-
-
Save sidonath/6d8bff4a444bf058c178 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Create | |
include Lotus::Action | |
expose :booking, :errors | |
def call(params) | |
@booking = Booking.new | |
# BookingForm validates datetime entered and converts the values into a single Time object | |
form = BookingForm.new(booking) | |
# Syncs the form values to the entity | |
form.sync(params) | |
# The contract validates that the booking is possible (no overlaps with other bookings) | |
contract = BookingContract.new(booking) | |
conract.validate | |
@errors = Errors.new(form, contract) | |
if errors.empty? | |
BookingRepository.save(booking) | |
else | |
throw 422 | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="/bookings" method="post"> | |
<% errors.each do |error| %> | |
<%= error %> | |
<% end %> | |
<label>When do you want to book a room?</label> | |
<select name="booked_for[day]">...</select> | |
<select name="booked_for[month]">...</select> | |
<select name="booked_for[year]">...</select> | |
<select name="booked_for[hour]">...</select> | |
<select name="booked_for[minute]">...</select> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment