Class: IshManager::NewsitemsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/newsitems_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject

Alphabetized : )



6
7
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
42
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 6

def create
  @newsitem = Newsitem.new params[:newsitem].permit!
  @resource ||= Ish::UserProfile.find params[:newsitem][:profile_id] if !params[:newsitem][:profile_id].blank?
  @resource ||= ::Gameui::Map.find params[:newsitem][:map_id] if !params[:newsitem][:map_id].blank?
  @resource.newsitems << @newsitem
  @resource.touch

  authorize! :create_newsitem, @resource

  if params[:photo]
    photo = Photo.create({
      descr:        params[:descr],
      photo:        params[:photo],
      subhead:      params[:subhead],
      user_profile: @current_profile,
    })
    @newsitem.photo = photo
  end

  url = case @resource.class.name
  when "Ish::UserProfile"
    user_profiles_path
  else
    root_path
  end

  flag = @newsitem.save && @resource.save
  if flag
    @resource.touch
    flash[:notice] = 'Success'
    redirect_to url
  else
    error = 'No Luck. ' + @newsitem.errors.messages.to_s  + " :: " + photo.errors.messages.to_s
    flash[:alert] = error
    render :action => :new
  end
end

#destroyObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 44

def destroy
  @newsitem = Newsitem.find params[:id]
  authorize! :destroy, @newsitem

  if @newsitem.destroy
    flash[:notice] = "Destroyed the newsitem."
  else
    flash[:alert] = "Cannot destroy the newsitem: #{@newsitem.errors.full_messages}."
  end

  redirect_to request.referrer ? request.referrer : '/'
end

#editObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 57

def edit
  @newsitem = Newsitem.find( params[:id] )
  authorize! :edit, @newsitem

  ## @TODO: what on earth is this?
  out = Gallery.unscoped.where( :is_trash => false, :user_profile => @current_profile ).order_by( :created_at => :desc )
  @galleries_list = [['', nil]] + out.map { |item| [ "#{item.created_at.strftime('%Y%m%d')} #{item.name}", item.id ] }

end

#indexObject



67
68
69
70
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 67

def index
  authorize! :newsitems_index, @resource
  @newsitems = @resource.newsitems
end

#newObject



72
73
74
75
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 72

def new
  @newsitem = Newsitem.new
  authorize! :new, @newsitem
end

#updateObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 77

def update
  @newsitem = Newsitem.find params[:id]
  authorize! :update, @newsitem

  if params[:photo]
    photo = Photo.new :photo => params[:photo]
    photo. = @current_profile
    @newsitem.photo = photo
  end

  flag = @newsitem.update_attributes params[:newsitem].permit!
  if flag
    flash[:notice] = 'Success'
  else
    flash[:alert] = "No Luck: #{@newsitem.errors.messages}"
  end

  if (@newsitem.map)
    redirect_to map_path(@newsitem.map)
  else
    redirect_to edit_newsitem_path(@newsitem)
  end

end