furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-18 18:04 UTC
hpricot results in an rhtml file
Hello, I have the following code in an rhtml file as part of a rails app: <html> <head> <title></title> </head> <body> <h1></h1> </body> <p>It is now <%= Time.now %></p> <p> <% require ''rubygems'' require ''hpricot'' require ''open-uri'' doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) puts doc %> </p> </html> Hpricot is doing it''s job and grabbing the mass.gov code, I can see it happening in the console. However, I can''t get the mass.gov code to display on the rhtml page. Is this even possible? What am I missing?'' Thanks, John --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<% # you''d be better off putting this part in the controller and get it out of the view. require ''rubygems'' require ''hpricot'' require ''open-uri'' @doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) -%> <%= @doc %> On 1/18/07, furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello, > > I have the following code in an rhtml file as part of a rails app: > <html> > <head> > <title></title> > </head> > <body> > <h1></h1> > </body> > <p>It is now <%= Time.now %></p> > <p> > > <% > require ''rubygems'' > require ''hpricot'' > require ''open-uri'' > > doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) > > puts doc > %> > </p> > </html> > > Hpricot is doing it''s job and grabbing the mass.gov code, I can see it > happening in the console. However, I can''t get the mass.gov code to > display on the rhtml page. > > Is this even possible? What am I missing?'' > > Thanks, > John > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jan 18, 2007 at 06:04:58PM -0000, furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Hello, > > I have the following code in an rhtml file as part of a rails app: > <html> > <head> > <title></title> > </head> > <body> > <h1></h1> > </body> > <p>It is now <%= Time.now %></p> > <p> > > <% > require ''rubygems'' > require ''hpricot'' > require ''open-uri'' > > doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) > > puts doc > %> > </p> > </html> > > Hpricot is doing it''s job and grabbing the mass.gov code, I can see it > happening in the console. However, I can''t get the mass.gov code to > display on the rhtml page. > > Is this even possible? What am I missing?''It''s certainly possible, it''s just that puts doesn''t do what you think it does. Also, most of that code should be in the helper, or possibly even in the controller. Consider this: ### helper file require ''hpricot'' require ''open-uri'' module FooHelper def processed_mass_gov_data doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) # I assume you have reason to use Hpricot rather than just putting the # retrieved HTML directly in the file, so this is where you''d do it doc.to_html end end ### view <html> <head> <title></title> </head> <body> <h1></h1> </body> <p>It is now <%= Time.now %></p> <p> <%= processed_mass_gov_data %> </p> </html>> Thanks, > John--Greg --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote the following on 18.01.2007 19:04 :> > Hello, > > I have the following code in an rhtml file as part of a rails app: > <html> > <head> > <title></title> > </head> > <body> > <h1></h1> > </body> > <p>It is now <%= Time.now %></p> > <p> > > <%use <%= instead of <% or nothing will be added to the page (the result of the block of code (if any) will be discarded).> require ''rubygems'' > require ''hpricot'' > require ''open-uri'' > > doc = Hpricot(open("http://www.mass.gov/legis/184history/h00024.htm")) > > puts dochere replace "puts doc" with "doc". puts ouputs on the standard output, not the page. If you replace it with "doc" only, it will be the result of the code block which is what you want.> %> > </p> > </html> >Lionel. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-18 21:48 UTC
Re: hpricot results in an rhtml file
If I did just want to place the retrieved HTML directly, how would I do that? Thanks for the help, obviously new to ROR. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jan 18, 2007 at 09:48:36PM -0000, furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> If I did just want to place the retrieved HTML directly, how would I do > that?<%= open(''http://blah...'').read %>> Thanks for the help, obviously new to ROR.--Greg --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I assume you''re going to process and massage that retrieved HTML, right? ''Cause as soon as the browser sees the retrieved </body> tag, I can''t imagine there wouldn''t be potential problems with the rest of your app [after the puts doc] showing up. And I''ll probably have nightmares about traversing the FrankenDOM! RSL On 1/18/07, Gregory Seidman <gsslist+ror-dNXPQ6k9rNiG6BJUYyje5axOck334EZe@public.gmane.org> wrote:> > > On Thu, Jan 18, 2007 at 09:48:36PM -0000, furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > If I did just want to place the retrieved HTML directly, how would I do > > that? > > <%= open(''http://blah...'').read %> > > > Thanks for the help, obviously new to ROR. > > --Greg > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-23 20:18 UTC
Re: hpricot results in an rhtml file
Greg, With this method, can I strip out certain tags, or have it just call certain tags? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Jan 23, 2007 at 08:18:17PM -0000, furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Greg, > > With this method, can I strip out certain tags, or have it just call > certain tags?You can do all sorts of magic with Hpricot. Just using open().read to splat it on the page won''t do that, however. It looks to me like you need to sit down with irb and figure out what steps you need to take to convert what you get from the original URL to what you actually want. Once you''ve gotten that code working dependably you can call it from the controller and put it in an instance variable, which you can refer to in the view. I may be mistaken, but it looks to me like you are trying to use Rails without actually learning Ruby. This is a mistake, and will not serve you well. I recommend David Black''s excellent book "Ruby for Rails" in this case, in addition to the pickaxe book.> Thanks.--Greg --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
furfey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-23 21:11 UTC
Re: hpricot results in an rhtml file
Thanks, and you''re right. I will check out the books you recommended. On Jan 23, 4:00 pm, Gregory Seidman <gsslist+...-dNXPQ6k9rNiG6BJUYyje5axOck334EZe@public.gmane.org> wrote:> On Tue, Jan 23, 2007 at 08:18:17PM -0000, fur...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > Greg, > > > With this method, can I strip out certain tags, or have it just call > > certain tags?You can do all sorts of magic with Hpricot. Just using open().read to splat > it on the page won''t do that, however. > > It looks to me like you need to sit down with irb and figure out what steps > you need to take to convert what you get from the original URL to what you > actually want. Once you''ve gotten that code working dependably you can call > it from the controller and put it in an instance variable, which you can > refer to in the view. > > I may be mistaken, but it looks to me like you are trying to use Rails > without actually learning Ruby. This is a mistake, and will not serve you > well. I recommend David Black''s excellent book "Ruby for Rails" in this > case, in addition to the pickaxe book. > > > Thanks.--Greg--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---