app/models/page_part.rb in mcms_pages-0.0.1 vs app/models/page_part.rb in mcms_pages-0.0.2

- old
+ new

@@ -26,74 +26,55 @@ attr_accessible :body, :page_id, :title, :page_parts_pages_attributes #validating title field to have non-blank value validates :title, :presence => true - # @param : none + # @param : string(title of the page part) # @return : array - # @purpose : To find all page_parts with title header - def self.find_page_parts_with_title_header + # @purpose : To find all page_parts with given title + def self.find_page_parts_with_title title #find all page parts with title header and assign it to a variable - header_part = self.find_all_by_title("header") + part_body = self.find_all_by_title(title) # calling method to find unique pages and assigning them to an array - page_title = PagePartsPage.find_unique_page_parts_pages(header_part) + page_title = PagePartsPage.find_unique_page_parts_pages(part_body) # returning the array return page_title - + end # end method # @param : none # @return : array - # @purpose : To find all page_parts with title header - def self.find_page_parts_with_title_footer + # @purpose : It will just return the title of page part + def self.find_page_parts_with_title_main_body - #find all page parts with title header and assign it to a variable - footer_part = self.find_all_by_title("footer") + return "main body" - # calling method to find unique pages and assigning them to an array - page_title = PagePartsPage.find_unique_page_parts_pages(footer_part) - - # returning the array - return page_title - end # end method - # @param : none - # @return : array - # @purpose : To find all page_parts with title right body - def self.find_page_parts_with_title_right_body + # @param : Object + # @return : none + # @purpose : To find all independent page_parts and delete it + def self.delete_page_parts page - #find all page parts with title header and assign it to a variable - right_body = self.find_all_by_title("right body") + # loop through page_parts_pages of page and check its page part + page.page_parts_pages.each do |page_part_page| - # calling method to find unique pages and assigning them to an array - page_title = PagePartsPage.find_unique_page_parts_pages(right_body) + # find page_part by its id and assign it to a variable + page_part = self.find_by_id(page_part_page.page_part_id) - # returning the array - return page_title + # if there is only one page_part for a page then delete it + if page_part.pages.count == 1 and page_part.pages.first.title == page.title - end # end method + # delete page_part + page_part.destroy - # @param : none - # @return : array - # @purpose : To find all page_parts with title left body - def self.find_page_parts_with_title_left_body + end # end if - #find all page parts with title header and assign it to a variable - left_body = self.find_all_by_title("left body") + end # end loop - # calling method to find unique pages and assigning them to an array - page_title = PagePartsPage.find_unique_page_parts_pages(left_body) - - # returning the array - return page_title - end # end method - def self.find_page_parts_with_title_main_body - return "main body" - end - -end # end class \ No newline at end of file +end # end class +