Class: Back::PostFieldsController
- Inherits:
-
BackController
- Object
- BackController
- Back::PostFieldsController
- Defined in:
- app/controllers/lato_blog/back/post_fields_controller.rb
Instance Method Summary collapse
-
#create_relay_field ⇒ Object
This function create a new field for the post.
- #destroy ⇒ Object
-
#destroy_relay_field ⇒ Object
This function destroy a post for the field.
- #index ⇒ Object
Instance Method Details
#create_relay_field ⇒ Object
This function create a new field for the post.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/lato_blog/back/post_fields_controller.rb', line 37 def create_relay_field # find post field @post_field = LatoBlog::PostField.find_by(id: params[:post_field_id]) unless @post_field @error = true respond_to { |r| r.js } end # find subfield info child_field_info = nil @post_field.[:fields].each do |key, content| child_field_info = [key, content] if key == params[:key] end unless child_field_info @error = true respond_to { |r| r.js } end # prepare data to create field child_field_key = child_field_info.first child_field_content = child_field_info.last # override class and position child_field_content[:class] = nil child_field_content[:position] = !@post_field.post_fields.empty? ? @post_field.post_fields.order('position ASC').last.position + 1 : 1 # create subfield for the post field blog__create_db_post_field(@post_field.post, child_field_key, child_field_content, @post_field) # send response to client @error = false respond_to { |r| r.js } end |
#destroy ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/lato_blog/back/post_fields_controller.rb', line 14 def destroy @post_field = LatoBlog::PostField.find_by(id: params[:id]) unless @post_field flash[:warning] = LANGUAGES[:lato_blog][:flashes][:post_field_not_found] redirect_to lato_blog.root_path return end unless @post_field.destroy flash[:danger] = @post_field.category_parent.errors..to_sentence redirect_to lato_blog.post_fields_path return end flash[:success] = LANGUAGES[:lato_blog][:flashes][:post_field_destroy_success] redirect_to lato_blog.post_fields_path end |
#destroy_relay_field ⇒ Object
This function destroy a post for the field.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/lato_blog/back/post_fields_controller.rb', line 67 def destroy_relay_field # find post field child_field = LatoBlog::PostField.find_by(id: params[:id]) @post_field = child_field.post_field unless @post_field @error = true respond_to { |r| r.js } end # find post field child and destroy it unless child_field.destroy @error = true respond_to { |r| r.js } end # send response to client @error = false respond_to { |r| r.js } end |
#index ⇒ Object
8 9 10 11 12 |
# File 'app/controllers/lato_blog/back/post_fields_controller.rb', line 8 def index core__set_header_active_page_title(LANGUAGES[:lato_blog][:pages][:post_fields]) @post_fields = LatoBlog::PostField.all.order('meta_visible') = (@post_fields, search: 'key', pagination: 10) end |