Class: ConstructorPages::FieldsController

Inherits:
ConstructorCore::AdminController
  • Object
show all
Includes:
ConstructorCore::DeviseHelper
Defined in:
app/controllers/constructor_pages/fields_controller.rb

Instance Method Summary collapse

Instance Method Details

#create ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/controllers/constructor_pages/fields_controller.rb', line 20

def create
  @field = Field.new params[:field]

  if @field.save
    redirect_to edit_template_path(@field.template_id), :notice => "Поле «#{@field.name}» успешно добавлено."
  else
    render :action => 'new', :template_id => @field.template_id
  end
end

#destroy ⇒ Object



40
41
42
43
44
45
46
# File 'app/controllers/constructor_pages/fields_controller.rb', line 40

def destroy
  @field = Field.find(params[:id])
  name = @field.name
  template = @field.template.id
  @field.destroy
  redirect_to edit_template_url(template), :notice => "Поле «#{name}» успешно удалено."
end

#edit ⇒ Object



15
16
17
18
# File 'app/controllers/constructor_pages/fields_controller.rb', line 15

def edit
  @field = Field.find(params[:id])
  @field.template = Template.find(params[:template_id])
end

#move_down ⇒ Object



54
55
56
57
58
# File 'app/controllers/constructor_pages/fields_controller.rb', line 54

def move_down
  @field = Field.find(params[:id])
  @field.move_lower
  redirect_to :back, :notice => 'Поле успешно перемещено.'
end

#move_up ⇒ Object



48
49
50
51
52
# File 'app/controllers/constructor_pages/fields_controller.rb', line 48

def move_up
  @field = Field.find(params[:id])
  @field.move_higher
  redirect_to :back, :notice => 'Поле успешно перемещено.'
end

#new ⇒ Object



10
11
12
13
# File 'app/controllers/constructor_pages/fields_controller.rb', line 10

def new
  @field = Field.new
  @field.template = Template.find(params[:template_id])
end

#update ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'app/controllers/constructor_pages/fields_controller.rb', line 30

def update
  @field = Field.find params[:id]

  if @field.update_attributes params[:field]
    redirect_to edit_template_url(@field.template.id), :notice => "Поле «#{@field.name}» успешно обновлено."
  else
    render :action => "edit"
  end
end