module Ems class ReportsController < ApplicationController load_and_authorize_resource # GET /reports # GET /reports.json def index @reports = Report.all respond_to do |format| format.html # index.html.erb format.json { render json: @reports } end end # GET /reports/1 # GET /reports/1.json def show @report = Report.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @report } end end # GET /reports/new # GET /reports/new.json def new @report = Report.new @report.assets.build @report.category = Category.find params[:category_id] respond_to do |format| format.html # new.html.erb format.json { render json: @report } end end # GET /reports/1/edit def edit @report = Report.find(params[:id]) @report.assets.build end # POST /reports # POST /reports.json def create @report = Report.new(params[:report]) respond_to do |format| if @report.save format.html { redirect_to edit_category_report_path(@report.category, @report), notice: 'Report was successfully created.' } format.json { render json: @report, status: :created, location: @report } else format.html { render action: "new", :category_id => @report.category, :id => @report } format.json { render json: @report.errors, status: :unprocessable_entity } end end end # PUT /reports/1 # PUT /reports/1.json def update @report = Report.find(params[:id]) respond_to do |format| if @report.update_attributes(params[:report]) format.html { redirect_to edit_category_report_path(@report.category, @report), notice: 'Report was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit", :category_id => @report.category, :id => @report } format.json { render json: @report.errors, status: :unprocessable_entity } end end end # DELETE /reports/1 # DELETE /reports/1.json def destroy @report = Report.find(params[:id]) category = @report.category @report.destroy respond_to do |format| format.html { redirect_to category_reports_path(category), notice: 'Report was successfully deleted.' } format.json { head :no_content } end end end end