Class: IshManager::NewsitemsController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
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
|
#destroy ⇒ Object
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
|
#edit ⇒ Object
57
58
59
60
|
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 57
def edit
@newsitem = Newsitem.find( params[:id] )
authorize! :edit, @newsitem
end
|
#index ⇒ Object
62
63
64
65
|
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 62
def index
authorize! :newsitems_index, @resource
@newsitems = @resource.newsitems
end
|
#new ⇒ Object
67
68
69
70
|
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 67
def new
@newsitem = Newsitem.new
authorize! :new, @newsitem
end
|
#update ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'app/controllers/ish_manager/newsitems_controller.rb', line 72
def update
@newsitem = Newsitem.find params[:id]
authorize! :update, @newsitem
if params[:photo]
photo = Photo.new :photo => params[:photo]
photo.user_profile = @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
|