Created
November 26, 2013 05:55
-
-
Save ricardodovalle/7654022 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 VehiclesController < ApplicationController | |
def index | |
@vehicles = current_tenant.vehicles | |
respond_to do |format| | |
format.html | |
format.json { render json: VehiclesDatatable.new(view_context) } | |
end | |
end | |
def show | |
@vehicle = get_vehicle(params[:id]) | |
end | |
def new | |
@vehicle = current_tenant.vehicles.new | |
respond_to do |format| | |
format.html | |
format.js | |
end | |
end | |
def edit | |
@vehicle = get_vehicle(params[:id]) | |
end | |
def create | |
@vehicle = current_tenant.vehicles.new(permitted_params.vehicle) | |
@vehicle.created_by = current_user.id | |
respond_to do |format| | |
if @vehicle.save | |
@vehicle.create_activity :create, owner: current_user, custom_action: 'create' | |
format.html { redirect_to @vehicle, notice: 'Vehicle was successfully created.' } | |
format.json { render json: @vehicle, status: :created, location: @vehicle } | |
else | |
format.html { render 'new' } | |
format.json { render json: @vehicle.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def update | |
@vehicle = get_vehicle(params[:id]) | |
respond_to do |format| | |
if @vehicle.update(permitted_params.vehicle) | |
@vehicle.create_activity :update, owner: current_user, custom_action: 'update' | |
format.html { redirect_to @vehicle, notice: 'Vehicle was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render 'edit' } | |
format.json { render json: @vehicle.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def destroy | |
@vehicle = get_vehicle(params[:id]) | |
@vehicle.inactivated_by(current_user) | |
respond_to do |format| | |
format.html { redirect_to :back } | |
format.json { head :no_content } | |
format.js | |
end | |
end | |
private | |
def get_vehicle(params_id) | |
current_tenant.vehicles.find(params_id) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment