Class: IshManager::ReportsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- IshManager::ReportsController
- Defined in:
- app/controllers/ish_manager/reports_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
alphabetized : ).
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
alphabetized : )
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 8 def create @report = Report.new params[:report].permit! @report.user_profile = @current_profile # @TODO: this should not be hard-coded :create, @report flag = @report.save respond_to do |format| if flag ## @TODO: I'm sure there is a better way if params[:report][:photo] photo = Photo.new photo.photo = params[:report][:photo] photo.is_public = @report.is_public photo.is_trash = false photo.report_id = @report.id photo.save end format.html do redirect_to report_path(@report), :notice => 'Report was successfully created.' end format.json { render :json => @report, :status => :created, :location => @report } # TODO: remove, I got the api now. else format.html do flash[:alert] = @report.errors. @tags_list = Tag.all.list render :action => "new" end format.json { render :json => @report.errors, :status => :unprocessable_entity } # @TODO: remove, right? no api here. end end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 43 def destroy @report = Report.unscoped.find params[:id] :destroy, @report @report.is_trash = true @report.save redirect_to request.referrer end |
#edit ⇒ Object
51 52 53 54 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 51 def edit @report = Report.unscoped.find params[:id] :edit, @report end |
#index ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 56 def index :index, Report @reports = Report.unscoped.order_by( :created_at => :desc ).where( :is_trash => false, :user_profile => @current_profile ).page( params[:reports_page] ).per( Report::PER_PAGE ) if params[:q] @reports = @reports.or({ slug: /#{params[:q]}/i }, { name: /#{params[:q]}}/i }) # @TODO: why can't I have space in search term? if @reports.length == 1 redirect_to report_path(@reports[0]) return end end end |
#new ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 70 def new @report = Report.new :new, @report @tags_list = Tag.all.where( :is_public => true ).list respond_to do |format| format.html do render end format.json { render :json => @report } end end |
#show ⇒ Object
83 84 85 86 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 83 def show @report = Report.unscoped.find params[:id] :show, @report end |
#update ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/ish_manager/reports_controller.rb', line 88 def update @report = Report.unscoped.find params[:id] :update, @report if params[:photo] photo = Photo.new :photo => params[:photo] @report.update_attributes( :photo => photo, :updated_at => Time.now ) end respond_to do |format| if @report.update_attributes(params[:report].permit!) format.html do redirect_to report_path(@report), :notice => 'Report was successfully updated.' end format.json { head :ok } else format.html { render :action => "edit" } format.json { render :json => @report.errors, :status => :unprocessable_entity } end end end |