Class: ConstructorPages::FieldsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ConstructorCore::ApplicationController
- ApplicationController
- ConstructorPages::FieldsController
- Defined in:
- pages/app/controllers/constructor_pages/fields_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'pages/app/controllers/constructor_pages/fields_controller.rb', line 13 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
44 45 46 47 48 49 |
# File 'pages/app/controllers/constructor_pages/fields_controller.rb', line 44 def destroy @field = Field.find(params[:id]) name, template = @field.name, @field.template.id @field.destroy redirect_to edit_template_url(template), notice: t(:field_success_removed, name: name) end |
#edit ⇒ Object
9 10 11 |
# File 'pages/app/controllers/constructor_pages/fields_controller.rb', line 9 def edit @field = Field.find(params[:id]).tap {|f| f.template = Template.find(params[:template_id])} end |
#new ⇒ Object
5 6 7 |
# File 'pages/app/controllers/constructor_pages/fields_controller.rb', line 5 def new @field = Field.new.tap {|f| f.template = Template.find(params[:template_id])} end |
#update ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'pages/app/controllers/constructor_pages/fields_controller.rb', line 23 def update @field = Field.find params[:id] unless @field.type_value == params[:field][:type_value] @field.type_class.where(field_id: @field.id).each do |field| "constructor_pages/types/#{params[:field][:type_value]}_type".classify.constantize.new( field_id: @field.id, page_id: field.page_id).tap {|f| f.value = field.value unless [@field.type_value, params[:field][:type_value]].include?('image') and (@field.type_value == 'string' and field.value.strip == '') f.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 |