Class: EditionsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#_edition_exists, #after_sign_in_path_for, #deny_access, #expansion_exists, #fill_platforms, #game_exists, #game_maker_only, #has_query, #ignore_referral_spam, #reviewer_only, #work_exists, #xhr_only

Instance Method Details

#createObject


36
37
38
39
40
41
42
43
44
# File 'app/controllers/editions_controller.rb', line 36

def create
	@edition = Edition.new(edition_params)
	work_option = params.permit(:work_option)[:work_option]
	if work_option == "existing"
		create_with_existing_work
	else
		create_with_new_work
	end
end

#do_transformObject


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/editions_controller.rb', line 76

def do_transform
	@edition = Edition.friendly.find(params[:id])
	@parent_edition = Edition.friendly.find(params[:parent_edition_id])

	transformed_expansion = Expansion.new()
	transformed_expansion.copy_from_edition(@edition)
	transformed_expansion.edition = @parent_edition
	transformed_expansion.save!

	old_work = @edition.work
	@edition.destroy
	if old_work.editions.length == 0
		old_work.destroy
	end

	redirect_to [transformed_expansion.edition, transformed_expansion]
end

#editObject


49
50
51
52
# File 'app/controllers/editions_controller.rb', line 49

def edit
	@edition = Edition.friendly.find(params[:id])
	@work = @edition.work
end

#existing_workObject


28
29
30
31
32
33
34
# File 'app/controllers/editions_controller.rb', line 28

def existing_work
	@work = Work.new(work_params)
	@existing_work = Work.friendly.find(params.require(:existing_work).permit(:id)[:id])
	respond_to do |format|
		  format.js
	end
end

#indexObject


46
47
48
# File 'app/controllers/editions_controller.rb', line 46

def index
	@editions = Edition.where(status: Edition.statuses[:active]).paginate(:page => params[:page]).order('title')
end

#newObject


22
23
24
25
26
27
# File 'app/controllers/editions_controller.rb', line 22

def new
	@edition = Edition.new
	@work = Work.friendly.find(params[:work_id])
	rescue ActiveRecord::RecordNotFound
		@work = Work.new
end

#showObject


64
65
66
67
68
69
70
71
# File 'app/controllers/editions_controller.rb', line 64

def show
	@edition = Edition.friendly.find(params[:id])
	@other_editions_count = Edition.get_other_active_editions_from_the_same_work(@edition).count()
	@other_editions = Edition.get_other_active_editions_from_the_same_work(@edition).limit(5)
	@description = GitHub::Markdown.render_gfm(@edition.description.present? ? @edition.description : "").html_safe
	@user_shelves = GameShelf.user_shelves(current_user.id) if current_user
	params[:platform] = @edition.platform_id.to_s
end

#transformObject


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

def transform
	@edition = Edition.friendly.find(params[:id])
	params[:platform] = @edition.platform_id.to_s
end

#updateObject


53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/editions_controller.rb', line 53

def update
	@edition = Edition.friendly.find(params[:id])
	@work = @edition.work
	@work.update_attributes!(work_params)
	@edition.update_attributes!(edition_params)
	flash[:notice] = "Your changes were saved!"
	redirect_to @edition

	rescue ActiveRecord::RecordInvalid
		render 'edit'
end