openURI not capturing pages from the same rails app

Hi,

I am using standard Ruby library openURI to capture the HTML code from
other pages. The problem openURI does not work for capturing pages from
the same rails application.

Here is the code:

class CdCreatorController < ApplicationController
require ‘open-uri’

def generate

lines = []

file = open("http://127.0.0.1:3001/cd_creator/product/1"){ |f|

f.each_line {|line| lines << line}}

@obj = lines

end

def product
@product = Product.find(params[:id]) {|f| f.each_line {|line| p
line} }

end
end

When I call method generate I get an TimeOut Error (execution expired).
But this method works just fine when I’m capturing pages from Internet
or local pages
with different port number.

Please help me.

i believe (someone correct me if i am wrong please) the answer is that
rails only handles one request at a time. what this means is that
your app is waiting for the current (external) request to finish in
order to handle the next (internal) request from your open() call.

can i ask why you need to access your app this particular way?

I know it sounds crazy, but could it be a DNS issue? Can your
webserver actually see itself? I ask this because I recently dealt
with a similar situation (not using rails, but ASP.NET) where the
webserver has some screwy DNS issues where internal calls to 127.0.0.1
or localhost weren’t routing properly. Even doing a ping to 127.0.0.1
from commandline wouldn’t work.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs