Class: BlogController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- BlogController
- Defined in:
- app/controllers/blog_controller.rb
Instance Method Summary collapse
- #index ⇒ Object
-
#update_data ⇒ Object
This is temporary and only to complete the import to SA’s site.
Instance Method Details
#index ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/blog_controller.rb', line 3 def index unless params[:tag] @posts = Page.for_blog.published.order('published_at desc').paginate(:page => params[:page], :per_page => 20) else @posts = Page.for_blog.published.tagged_with(params[:tag]).order('published_at desc').paginate(:page => params[:page], :per_page => 20) end respond_to do |format| format.html { render :layout => 'blog' } format.atom end end |
#update_data ⇒ Object
This is temporary and only to complete the import to SA’s site.
16 17 18 19 20 21 22 23 24 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/blog_controller.rb', line 16 def update_data @count = 0 @pages = Array.new Page.all.each do |page| # determine whether page contains path if page.body.match /src="\/system\/photos\/.*\.jpg/ # extract string to be changed # match_data = page.body.match /src="\/system\/photos\/.*\.jpg/ # # extract an image name with jpg extension in the blog/2006 section # extracted_image = match_data.to_s.sub("src=\"/images/photos/", '') # # find the corresponding illustration # illustration = Illustration.find_by_name(extracted_image) # if illustration # # change the image path # page.body = page.body.sub("/images/blog/2007/", "/system/images/illustration/#{illustration.id}/large_") # # save the page with new path # page.save # end @count += 1 @pages << page end end # @list_of_files = Array.new # @count = 0 # Illustration.all.each do |illustration| # # if illustration.name == 'No name given' # # illustration.destroy # @count += 1 # # end # # # # extract an image name with jpg extension in the blog/2006 section # # extracted_image = page.body.match(/src="\/images\/blog\/2006\/.*\.jpg/).to_s.sub("src=\"/images/blog/2006/", '') # # # # if extracted_image # # # # # find the corresponding illustration # # @illustration = Illustration.find_by_image(File.basename("/Users/swamiatma/Documents/railsapps/aya/public/images/blog/2006/#{extracted_image}")) # # # # if @illustration # # # change the path of the image # # page.body = page.body.sub("/images/blog/2006/", "/system/images/illustration/#{@illustration.id}/large_") # # # save the page with new path # # page.save # # # # count += 1 # # extracted_image = nil # # end # # # # end # # end # # take a blog post as an example # @page = Page.find(9) # redirect_to blog_path, notice: "#{count} wp images have been detected" # # count = 0 # # Dir["/Users/swamiatma/Documents/railsapps/aya/public/images/photos/*.*"].each do |file| # # illustration = Illustration.new # illustration.image = File.open(file) # illustration.name = "photos-#{File.basename(file)}" # illustration.save # # count += 1 # # end # # # redirect_to illustrations_path, notice: "#{count} new illustrations should be uploaded" end |