Eric J. Gruber
2009-Sep-30 15:44 UTC
What is the Ruby on Rails equivalent to php includes?
If I was to include a file (such as in a template) in php to use across a large number of pages, I would write this: <?php include (''navigation.html''); ?> In turn, every time I used this code, it would “include” (or better put, display) the content of navigation.html in the browser. I can’t figure out how to do this is Rails. When building my layouts, how can I include a file like this, like I would in PHP. I have files I’d like to include remotely, but not sure how to get this done. Any ideas?
Greg Donald
2009-Sep-30 15:48 UTC
Re: What is the Ruby on Rails equivalent to php includes?
On Wed, Sep 30, 2009 at 10:44 AM, Eric J. Gruber <eric-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> > If I was to include a file (such as in a template) in php to use > across a large number of pages, I would write this: > <?php include (''navigation.html''); ?> > > In turn, every time I used this code, it would “include” (or better > put, display) the content of navigation.html in the browser. > > I can’t figure out how to do this is Rails. When building my layouts, > how can I include a file like this, like I would in PHP. I have files > I’d like to include remotely, but not sure how to get this done. > > Any ideas?render :partial => ''foo/bar'' -- Greg Donald http://destiney.com/
Eric Gruber
2009-Sep-30 16:00 UTC
Re: What is the Ruby on Rails equivalent to php includes?
I tried that, with something like this: <%= render :partial => ''http://example.com/navigation.html'' %> And I got the "We''re sorry, but something went wrong." page from my app. I am 100% positive the server I''m trying to include the file from allows files to re used remotely. On Sep 30, 10:48 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Sep 30, 2009 at 10:44 AM, Eric J. Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > > > > If I was to include a file (such as in a template) in php to use > > across a large number of pages, I would write this: > > <?php include (''navigation.html''); ?> > > > In turn, every time I used this code, it would “include” (or better > > put, display) the content of navigation.html in the browser. > > > I can’t figure out how to do this is Rails. When building my layouts, > > how can I include a file like this, like I would in PHP. I have files > > I’d like to include remotely, but not sure how to get this done. > > > Any ideas? > > render :partial => ''foo/bar'' > > -- > Greg Donaldhttp://destiney.com/
Greg Donald
2009-Sep-30 16:02 UTC
Re: What is the Ruby on Rails equivalent to php includes?
On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber <eric-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> <%= render :partial => ''http://example.com/navigation.html'' %>The partial file should be local to the Rails app. -- Greg Donald http://destiney.com/
Jason Roelofs
2009-Sep-30 16:03 UTC
Re: What is the Ruby on Rails equivalent to php includes?
You can''t do that. render works only with files local to your app. Jason On Wed, Sep 30, 2009 at 12:00 PM, Eric Gruber <eric-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> > I tried that, with something like this: > > > <%= render :partial => ''http://example.com/navigation.html'' %> > > And I got the "We''re sorry, but something went wrong." page from my > app. > > I am 100% positive the server I''m trying to include the file from > allows files to re used remotely. > > > On Sep 30, 10:48 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Wed, Sep 30, 2009 at 10:44 AM, Eric J. Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> > wrote: > > > > > > > > > If I was to include a file (such as in a template) in php to use > > > across a large number of pages, I would write this: > > > <?php include (''navigation.html''); ?> > > > > > In turn, every time I used this code, it would “include” (or better > > > put, display) the content of navigation.html in the browser. > > > > > I can’t figure out how to do this is Rails. When building my layouts, > > > how can I include a file like this, like I would in PHP. I have files > > > I’d like to include remotely, but not sure how to get this done. > > > > > Any ideas? > > > > render :partial => ''foo/bar'' > > > > -- > > Greg Donaldhttp://destiney.com/ > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Gruber
2009-Sep-30 16:04 UTC
Re: What is the Ruby on Rails equivalent to php includes?
Right. That helps if the file I am using is locally. But what do I do if that file is from another server? On Sep 30, 11:02 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > <%= render :partial => ''http://example.com/navigation.html''%> > > The partial file should be local to the Rails app. > > -- > Greg Donaldhttp://destiney.com/
Eric Gruber
2009-Sep-30 16:06 UTC
Re: What is the Ruby on Rails equivalent to php includes?
OK ... so is there another way to do it without using render? Surely this isn''t something that PHP can do that Rails can''t. On Sep 30, 11:04 am, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> Right. That helps if the file I am using is locally. But what do I do > if that file is from another server? > > On Sep 30, 11:02 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > > <%= render :partial => ''http://example.com/navigation.html''%> > > > The partial file should be local to the Rails app. > > > -- > > Greg Donaldhttp://destiney.com/
John Barnette
2009-Sep-30 16:13 UTC
Re: What is the Ruby on Rails equivalent to php includes?
On Sep 30, 2009, at 9:06 AM, Eric Gruber wrote:> OK ... so is there another way to do it without using render? > > Surely this isn''t something that PHP can do that Rails can''t.This is a terrible idea. But hey, here, have a loaded gun: <%= open("http://example.com/navigation.html").read %> ~ j.> > On Sep 30, 11:04 am, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: >> Right. That helps if the file I am using is locally. But what do I do >> if that file is from another server? >> >> On Sep 30, 11:02 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber >>> <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: >>>> <%= render :partial => ''http://example.com/navigation.html''%> >> >>> The partial file should be local to the Rails app. >> >>> -- >>> Greg Donaldhttp://destiney.com/ > >
Eric Gruber
2009-Sep-30 16:17 UTC
Re: What is the Ruby on Rails equivalent to php includes?
If there''s some sort of risk, please inform. Not that it matters, that didn''t work either. On Sep 30, 11:13 am, John Barnette <jbarne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 30, 2009, at 9:06 AM, Eric Gruber wrote: > > > OK ... so is there another way to do it without using render? > > > Surely this isn''t something that PHP can do that Rails can''t. > > This is a terrible idea. But hey, here, have a loaded gun: > > <%= open("http://example.com/navigation.html").read %> > > ~ j. > > > > > On Sep 30, 11:04 am, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > >> Right. That helps if the file I am using is locally. But what do I do > >> if that file is from another server? > > >> On Sep 30, 11:02 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber > >>> <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > >>>> <%= render :partial => ''http://example.com/navigation.html''%> > > >>> The partial file should be local to the Rails app. > > >>> -- > >>> Greg Donaldhttp://destiney.com/
Eric Gruber
2009-Sep-30 16:43 UTC
Re: What is the Ruby on Rails equivalent to php includes?
I should clarify. 1. I control both servers that I''m working with, so the security risk is practically nil. 2. The app is very small. Any performance hits I''d take by including a remote file is acceptable. That said, still don''t have a fix. Thanx. Eric On Sep 30, 11:17 am, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> If there''s some sort of risk, please inform. > > Not that it matters, that didn''t work either. > > On Sep 30, 11:13 am, John Barnette <jbarne...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Sep 30, 2009, at 9:06 AM, Eric Gruber wrote: > > > > OK ... so is there another way to do it without using render? > > > > Surely this isn''t something that PHP can do that Rails can''t. > > > This is a terrible idea. But hey, here, have a loaded gun: > > > <%= open("http://example.com/navigation.html").read %> > > > ~ j. > > > > On Sep 30, 11:04 am, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > >> Right. That helps if the file I am using is locally. But what do I do > > >> if that file is from another server? > > > >> On Sep 30, 11:02 am, Greg Donald <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>> On Wed, Sep 30, 2009 at 11:00 AM, Eric Gruber > > >>> <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > >>>> <%= render :partial => ''http://example.com/navigation.html''%> > > > >>> The partial file should be local to the Rails app. > > > >>> -- > > >>> Greg Donaldhttp://destiney.com/
Marnen Laibow-Koser
2009-Sep-30 16:56 UTC
Re: What is the Ruby on Rails equivalent to php includes?
Eric Gruber wrote:> If there''s some sort of risk, please inform.I agree, this is a terrible idea from both performance and architectural perspectives. Why do you want your navbar to live on another server?> > Not that it matters, that didn''t work either.What happened when you tried the open().read solution? Just saying that it didn''t work isn''t that helpful. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Eric Gruber
2009-Sep-30 17:07 UTC
Re: What is the Ruby on Rails equivalent to php includes?
What happened was I got the "We''re sorry, but something went wrong." page from my app. I would prefer it all to be on one server, but the company I''m trying to do this for has many different projects, using different languages on two different servers. I''d rather not include a copy on the second server, so if I have to make a change to that one file (remember kids, don''t repeat yourself!) I have to only do it once on one server. On Sep 30, 11:56 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> Eric Gruber wrote: > > If there''s some sort of risk, please inform. > > I agree, this is a terrible idea from both performance and architectural > perspectives. Why do you want your navbar to live on another server? > > > > > Not that it matters, that didn''t work either. > > What happened when you tried the open().read solution? Just saying that > it didn''t work isn''t that helpful. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted viahttp://www.ruby-forum.com/.
Eric Gruber
2009-Sep-30 17:08 UTC
Re: What is the Ruby on Rails equivalent to php includes?
What happened was I got the "We''re sorry, but something went wrong." page from my app. I would prefer it all to be on one server, but the company I''m trying to do this for has many different projects, using different languages on two different servers. I''d rather not include a copy on the second server, so if I have to make a change to that one file (remember kids, don''t repeat yourself!) I have to only do it once on one server. On Sep 30, 11:56 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> Eric Gruber wrote: > > If there''s some sort of risk, please inform. > > I agree, this is a terrible idea from both performance and architectural > perspectives. Why do you want your navbar to live on another server? > > > > > Not that it matters, that didn''t work either. > > What happened when you tried the open().read solution? Just saying that > it didn''t work isn''t that helpful. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > -- > Posted viahttp://www.ruby-forum.com/.
Marnen Laibow-Koser
2009-Sep-30 17:15 UTC
Re: What is the Ruby on Rails equivalent to php includes?
Eric Gruber wrote:> What happened was I got the "We''re sorry, but something went wrong." > page from my > app.Yes, that''s all you will get on the screen in dev mode. What''s in the log?> > I would prefer it all to be on one server, but the company I''m trying > to do this for has many different projects, using different languages > on two different servers. I''d rather not include a copy on the second > server, so if I have to make a change to that one file (remember kids, > don''t repeat yourself!) I have to only do it once on one server.If you can''t set up a caching mechanism for the navbar, then this would be one of a very few cases in which I might actually recommend an iframe. But let me see if I can come up with an answer to your original question...> > > On Sep 30, 11:56�am, Marnen Laibow-Koser <rails-mailing-l...@andreas-Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Mauricio Szabo
2009-Sep-30 17:16 UTC
Re: What is the Ruby on Rails equivalent to php includes?
You must require ''open-uri'' to be able to open URLS. For example:>> open("http://example.com/").readErrno::ENOENT: No such file or directory - http://example.com/ from (irb):2:in `initialize'' from (irb):2:in `open'' from (irb):2 But if you require ''open-uri'':>> require ''open-uri''=> true>> open("http://example.com/").read=> "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r \n<body> \r\n<p>You have reached this web page by typing"example.com",\r\n"example.net",\r\n or "example.org" into your web browser.</p>\r\n<p>These domain names are reserved for use in documentation and are not available \r \n for registration. See <a href="http://www.rfc-editor.org/rfc/ rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r \n\r\n" On Sep 30, 2:07 pm, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote:> What happened was I got the "We''re sorry, but something went wrong." > page from my > app. > > I would prefer it all to be on one server, but the company I''m trying > to do this for has many different projects, using different languages > on two different servers. I''d rather not include a copy on the second > server, so if I have to make a change to that one file (remember kids, > don''t repeat yourself!) I have to only do it once on one server. > > On Sep 30, 11:56 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- > > s.net> wrote: > > Eric Gruber wrote: > > > If there''s some sort of risk, please inform. > > > I agree, this is a terrible idea from both performance and architectural > > perspectives. Why do you want your navbar to live on another server? > > > > Not that it matters, that didn''t work either. > > > What happened when you tried the open().read solution? Just saying that > > it didn''t work isn''t that helpful. > > > Best, > > -- > > Marnen Laibow-Koserhttp://www.marnen.org > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > -- > > Posted viahttp://www.ruby-forum.com/.
Eric Gruber
2009-Sep-30 18:15 UTC
Re: What is the Ruby on Rails equivalent to php includes?
Right on, that worked for me. Thanx so much! On Sep 30, 12:16 pm, Mauricio Szabo <mauricio.sz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You must require ''open-uri'' to be able to open URLS. For example: > > >> open("http://example.com/").read > > Errno::ENOENT: No such file or directory -http://example.com/ > from (irb):2:in `initialize'' > from (irb):2:in `open'' > from (irb):2 > > But if you require ''open-uri'': > > >> require ''open-uri'' > => true > >> open("http://example.com/").read > > => "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r > \n<body> \r\n<p>You have reached this web page by > typing"example.com",\r\n"example.net",\r\n or > "example.org" into your web browser.</p>\r\n<p>These domain > names are reserved for use in documentation and are not available \r > \n for registration. See <a href="http://www.rfc-editor.org/rfc/ > rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r > \n\r\n" > > On Sep 30, 2:07 pm, Eric Gruber <e...-XGWyyMbmuCAI8iZMlb555w@public.gmane.org> wrote: > > > What happened was I got the "We''re sorry, but something went wrong." > > page from my > > app. > > > I would prefer it all to be on one server, but the company I''m trying > > to do this for has many different projects, using different languages > > on two different servers. I''d rather not include a copy on the second > > server, so if I have to make a change to that one file (remember kids, > > don''t repeat yourself!) I have to only do it once on one server. > > > On Sep 30, 11:56 am, Marnen Laibow-Koser <rails-mailing-l...@andreas- > > > s.net> wrote: > > > Eric Gruber wrote: > > > > If there''s some sort of risk, please inform. > > > > I agree, this is a terrible idea from both performance and architectural > > > perspectives. Why do you want your navbar to live on another server? > > > > > Not that it matters, that didn''t work either. > > > > What happened when you tried the open().read solution? Just saying that > > > it didn''t work isn''t that helpful. > > > > Best, > > > -- > > > Marnen Laibow-Koserhttp://www.marnen.org > > > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > > > -- > > > Posted viahttp://www.ruby-forum.com/.
Robert Walker
2009-Oct-01 00:08 UTC
Re: What is the Ruby on Rails equivalent to php includes?
Mauricio Szabo wrote:> But if you require ''open-uri'': > >>> require ''open-uri'' > => true >>> open("http://example.com/").read > => "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r > \n<body> \r\n<p>You have reached this web page by > typing"example.com",\r\n"example.net",\r\n or > "example.org" into your web browser.</p>\r\n<p>These domain > names are reserved for use in documentation and are not available \r > \n for registration. See <a href="http://www.rfc-editor.org/rfc/ > rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r > \n\r\n"Wow! This is a bad idea. Including a full page inside another page just makes my skin crawl. If I absolutely had to do something like this I would maybe grab the page using open(...), but then strip out only the contents inside the body tag and render that inside the final page. Otherwise you''ll never be able to get a clean validation anything using that "navbar page." -- Posted via http://www.ruby-forum.com/.
Greg Donald
2009-Oct-01 01:00 UTC
Re: What is the Ruby on Rails equivalent to php includes?
On Wed, Sep 30, 2009 at 7:08 PM, Robert Walker <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Wow! This is a bad idea. Including a full page inside another page just > makes my skin crawl. If I absolutely had to do something like this I > would maybe grab the page using open(...), but then strip out only the > contents inside the body tag and render that inside the final page. > Otherwise you''ll never be able to get a clean validation anything using > that "navbar page."And think of how b0rken the stats will be for the server hosting the navbar.html. That''s enough to make wanna vomit. *quiver* -- Greg Donald http://destiney.com/
2009/10/1 Robert Walker <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Mauricio Szabo wrote: > >> But if you require ''open-uri'': >> >>>> require ''open-uri'' >> => true >>>> open("http://example.com/").read >> => "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r >> \n<body> \r\n<p>You have reached this web page by >> typing"example.com",\r\n"example.net",\r\n or >> "example.org" into your web browser.</p>\r\n<p>These domain >> names are reserved for use in documentation and are not available \r >> \n for registration. See <a href="http://www.rfc-editor.org/rfc/ >> rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r >> \n\r\n" > > Wow! This is a bad idea. Including a full page inside another page just > makes my skin crawl. If I absolutely had to do something like this I > would maybe grab the page using open(...), but then strip out only the > contents inside the body tag and render that inside the final page. > Otherwise you''ll never be able to get a clean validation anything using > that "navbar page." > --I don''t believe the OP ever said that it would be a full page that he would be including. He is just trying to access partials from one of his servers on another. Presumably some of the data for the remote one is not accessible to the local one. Colin