Created
March 2, 2016 20:12
-
-
Save austinklenk/2b74521f0c474eaecb3a 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 CampersController < ApplicationController | |
before_action :set_camper, only: [:show, :edit, :update, :destroy] | |
# before_action :set_customer, only: [:index, :new, :edit, :create, :update] | |
load_and_authorize_resource | |
# GET /campers | |
# GET /campers.json | |
def index | |
@campers = @customer.campers | |
end | |
def list | |
query = params[:q].presence || "" | |
@campers = Camper.search(query, page: params[:page], per_page: 20, order: {created_at: :desc} ) | |
end | |
# GET /campers/1 | |
# GET /campers/1.js | |
def show | |
@appointments = @camper.appointments | |
respond_to do |format| | |
format.html | |
format.json | |
end | |
end | |
# GET /campers/new | |
def new | |
@customer = Customer.find(params[:customer_id]) | |
@camper = @customer.campers.build | |
end | |
# GET /campers/1/edit | |
def edit | |
end | |
def page_name | |
"Campers" | |
end | |
# POST /campers | |
# POST /campers.json | |
def create | |
@camper = Camper.new(camper_params) | |
respond_to do |format| | |
if @camper.save | |
format.html { redirect_to camper_path(@camper), notice: 'Camper was successfully created.' } | |
format.json { render :show, status: :created, location: @camper } | |
else | |
format.html { render :new } | |
format.json { render json: @camper.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /campers/1 | |
# PATCH/PUT /campers/1.json | |
def update | |
respond_to do |format| | |
if @camper.update(camper_params) | |
format.html { redirect_to camper_path(@camper), notice: 'Camper was successfully updated.' } | |
format.json { render :show, status: :ok, location: @camper } | |
else | |
format.html { render :edit } | |
format.json { render json: @camper.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /campers/1 | |
# DELETE /campers/1.json | |
def destroy | |
@camper.destroy | |
respond_to do |format| | |
format.html { redirect_to root_path, notice: 'Camper was successfully deleted.' } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_camper | |
@camper = Camper.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def camper_params | |
params.require(:camper).permit(:order_id, :customer_id, :year, :manufacturer, :modelName, :camperClass, :vin, :mileage, :notes, :user_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment