SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP style include

    How do you do an include in a view using a url similar to a php include. I need to pull a common nav bar using a URL and in PHP of course I'd do
    PHP Code:
    include_once "http://www.domain.com/inc/nav_bar.php" 
    Can't for the life of me find out how to do this.
    Erh

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)

  3. #3
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Maybe I need an example because I don't see how this works. The docs don't mention anything about using full URL's to render external content like this and doing something like this:
    [code]
    render ( : partial=>"http://www.domain.com/inc/nav_bar.php")
    [/cope]
    gives an error about @nav_bar.php not being a valid instance variable name.

    I'm feeling very dense about this problem. Am I missing something as an option?
    Erh

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    You can't do includes through HTTP that way. Partials provide "include" functionality, but it's done in a different way than a PHP include is.

    Why not just stick your navigation in a layout? Then you still get the benefit of only having one place to edit it for a sitewide change.

  5. #5
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Why not just stick your navigation in a layout? Then you still get the benefit of only having one place to edit it for a sitewide change.
    Mostly because this is an externally maintained piece of html. I work at a university and this nav bar is from the main univeristy web group. It would be easier not to have to keep tabs on changes they might make to it if I can just use the URL include method to include it in my departments pages.

    So currently there is no way in Rails or Ruby to do this?
    Erh

  6. #6
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Found it.

    in environment.rb (or whever you want)
    Code:
    require 'net/http'
    require 'uri'
    And then I just used:
    Code:
    <%= Net::HTTP.get URI.parse("http://www.domain.com/inc/nav_bar.php") %>
    From the Ruby standard library.
    Erh

  7. #7
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it is wise to cache that...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •