Class: ConstructorPages::FieldsController
- Inherits:
-
ConstructorCore::ApplicationController
- Object
- ConstructorCore::ApplicationController
- ConstructorPages::FieldsController
- Defined in:
- app/controllers/constructor_pages/fields_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/constructor_pages/fields_controller.rb', line 15 def create @field = Field.new field_params if @field.save redirect_to edit_template_path(@field.template_id), notice: t(:field_success_added, name: @field.name) else render :action => 'new', :template_id => @field.template_id end end |
#destroy ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/controllers/constructor_pages/fields_controller.rb', line 52 def destroy @field = Field.find(params[:id]) name = @field.name template = @field.template.id @field.destroy redirect_to edit_template_url(template), notice: t(:field_success_removed, name: name) end |
#edit ⇒ Object
10 11 12 13 |
# File 'app/controllers/constructor_pages/fields_controller.rb', line 10 def edit @field = Field.find(params[:id]) @field.template = Template.find(params[:template_id]) end |
#new ⇒ Object
5 6 7 8 |
# File 'app/controllers/constructor_pages/fields_controller.rb', line 5 def new @field = Field.new @field.template = Template.find(params[:template_id]) end |
#update ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/constructor_pages/fields_controller.rb', line 25 def update @field = Field.find params[:id] if @field.type_value != params[:field][:type_value] @field.type_class.where(:field_id => @field.id).each do |field| new_field = "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new( :field_id => @field.id, :page_id => field.page_id) if @field.type_value != 'image' \ and params[:field][:type_value] != 'image' \ and not (@field.type_value == 'string' and field.value.strip == '') new_field.value = field.value end new_field.save field.destroy end end if @field.update field_params redirect_to edit_template_url(@field.template.id), notice: t(:field_success_updated, name: @field.name) else render :action => "edit" end end |