Class: ConstructorPages::ApplicationController

Inherits:
ConstructorCore::ApplicationController
  • Object
show all
Defined in:
app/controllers/constructor_pages/application_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.movable(what) ⇒ Object


5
6
7
# File 'app/controllers/constructor_pages/application_controller.rb', line 5

def self.movable(what)
  %w{up down}.each {|m| define_method "move_#{m}" do move_to what, params[:id], m.to_sym end}
end

Instance Method Details

#move_to(what, id, to) ⇒ Object


9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/constructor_pages/application_controller.rb', line 9

def move_to(what, id, to)
  from = ('constructor_pages/'+what.to_s).classify.constantize.find(id)
  to_sibling = to == :up ? from.left_sibling : from.right_sibling

  if not to_sibling.nil? and from.move_possible?(to_sibling)
    to == :up ? from.move_left : from.move_right
  end

  redirect_to :back
end