Thanks Fred,

I checked it out, and you were right. Open-URI is required now, and it
works like a charm.


Casen

On Jan 24, 2:11 pm, Frederick Cheung <[email protected]>
wrote:
> On 24 Jan 2009, at 10:39,cdubdwrote:
>
>
>
> > oh and I thought I should provide the error message itself:
>
> > NoMethodError (undefined method `read' for #<URI::HTTP:0x256f764>):
>
> URI does not have an read method. OpenURI adds one, so the logical  
> conclusion for me is that something in your environment has changed  
> that results in openuri not having been required when previously it was.
>
> Fred
>
>
>
> > On Jan 24, 1:41 am,cdubd<[email protected]> wrote:
> >> Hey Everyone,
>
> >> I have a pretty interesting problem that I thought I would try and  
> >> get
> >> some feedback on. The following method below accepts a URL string  
> >> as a
> >> parameter ex "http://www.google.com,"; and it uses regular expressions
> >> to try and find the images in the html. The odd thing is.... that I
> >> have tested it over and over again.... and it has always grabbed the
> >> images and worked exactly as I coded it too, but lately it has been
> >> telling me that the URI class doesn't have a read method.... when it
> >> must because I have been using it!
>
> >> I am just so confused why rails would suddenly have this issue, and I
> >> am wondering if anyone can make heads or tails out of it. The code is
> >> posted below.
>
> >> Thanks!
>
> >> <================== CODE ===========================================>
>
> >> def get_images(url)
> >>     @image_links = []
>
> >>     if validate_link(url) == false
> >>       return @image_links
> >>     end
>
> >>     if ((url =~ /\.jpg/)||(url =~ /\.png/)||(url =~ /\.gif/)) == nil
> >>         begin
> >>           uri = URI.parse(url)
> >>           str = uri.read
> >>           host = uri.host
> >>         rescue SystemCallError
> >>           return @image_links
>
> >>         end
>
> >>         @body = str.scan(/<body.+<\/body>/)
> >>         @images = str.scan(/(src=\"http.+\.jpg?\")/)
> >>         str = @images.to_s
> >>         @images = str.scan(/\".+?\"/)
> >>         @image_links = filter_images(@images)
> >>         @image_links.push("no_image.jpg")
> >>     else
> >>           @image_links.push(url)
> >>           @image_links.push("no_image.jpg")
> >>     end
>
> >>     return @image_links
> >>   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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to