Hi all,
I have created a ruby script which scraps the video url from a
website I want to implement it in rails I tried to implement it but I
am unable to implement it it shows [[undefined method `save' for
[]:Array]].......


Here is my controller code

class DevourController < ApplicationController
require 'net/http'
require 'open-uri'
def index
source =[]
array = Array.new
for path in 1..2
puts "Currently Executing Page No:----#{path}"
source = Net::HTTP.get('devour.com',"/#{path}")
html_tags=source.scan(/https?:[^"]*|http?:[^']*/)
#html_tags.gsub(/['"]/)
#puts html_tags
videos=[]
html_tags.each do |links|
videos << links if links.include?("/video/")
end
videos.uniq!
#puts videos.size
l=[]
videos.each do |y|
l << y.chomp('/')
array << l
end
puts l
puts "Successfully Executed"
end
array.uniq!
#puts l
puts array
puts array.size
puts "**********************************"
#Executing The Links To Get The Video Links
@original =[]
array.each do |f|
f.each do |url|
puts url.class
puts url
uri=URI(url)
@original << Net::HTTP.get(uri)
end
end
puts @original
puts @original.size
end

def create
@original=Link.all
@original.save
end

end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Surya at Dec 21, 2011 at 5:52 am
    Your @original object seems to be an Array instead of an Active Record
    object. So all you have to do is to loop through the @original and for each
    value save the data.
    On Wed, Dec 21, 2011 at 11:07 AM, MUMU wrote:

    Hi all,
    I have created a ruby script which scraps the video url from a
    website I want to implement it in rails I tried to implement it but I
    am unable to implement it it shows [[undefined method `save' for
    []:Array]].......


    Here is my controller code

    class DevourController < ApplicationController
    require 'net/http'
    require 'open-uri'
    def index
    source =[]
    array = Array.new
    for path in 1..2
    puts "Currently Executing Page No:----#{path}"
    source = Net::HTTP.get('devour.com',"/#{path}")
    html_tags=source.scan(/https?:[^"]*|http?:[^']*/)
    #html_tags.gsub(/['"]/)
    #puts html_tags
    videos=[]
    html_tags.each do |links|
    videos << links if links.include?("/video/")
    end
    videos.uniq!
    #puts videos.size
    l=[]
    videos.each do |y|
    l << y.chomp('/')
    array << l
    end
    puts l
    puts "Successfully Executed"
    end
    array.uniq!
    #puts l
    puts array
    puts array.size
    puts "**********************************"
    #Executing The Links To Get The Video Links
    @original =[]
    array.each do |f|
    f.each do |url|
    puts url.class
    puts url
    uri=URI(url)
    @original << Net::HTTP.get(uri)
    end
    end
    puts @original
    puts @original.size
    end

    def create
    @original=Link.all
    @original.save
    end

    end

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to
    rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/rubyonrails-talk?hl=en.

    --

    Please consider the environment before printing this email.

    Regards,
    Surya

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 21, '11 at 5:37a
activeDec 21, '11 at 5:52a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Surya: 1 post MUMU: 1 post

People

Translate

site design / logo © 2021 Grokbase