So I'm working on a Rails application that involves a dog daycare. I'm trying to do a helper that will eventually aide in reservation validation but for now I'm just trying to get it to show all kennels from the Reservations table and put those names into an array
Here's the error I'm getting error image
Here's the code from the reservation helper:
module ReservationsHelper
def available_kennels
availability = Array.new
@r.all.each do|kennel|
availability.push(kennel)
end
return availability
end
end
In the reservation controller, I'm assigning @r to reservation.all
Here's the controller:
class ReservationsController < ApplicationController
def new
@reservation = Reservation.new
@d = current_user.dogs
@r = reservation.all
end
def create
@reservation = current_user.reservations.build(r_params)
if @reservation.save
flash[:success] = "Reservation has been made"
else
render new
end
end
def r_params
params.require(:reservation).permit(:dog_id, :kennel_id, :startdate, :enddate, :status, :report)
end
end
As for kennels, the only thing this table has the standard id and name.
I know I'm sort of close.
Reservation.allinstead ofreservation.all.@dand@rmay save you a few key strokes. But, IMO, it can make your code harder to read and follow (for the future you and potential collaborators).