SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Executing php code in rails

    Hello guys. How could I execute a php script from RoR templates?

    I've tried to do that in such way:
    <% command = 'php /site/script.php uri=' %>
    <%= `#{command}` %>

    And got this:
    X-Powered-By: PHP/4.4.7 Content-type: text/html require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired require "dispatcher" ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun) Dispatcher.dispatch

    What I've done wrong?
    http://www.ebookspirate.com - one page ebook aggregator

  2. #2
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure my test with the following code worked wonderfully...

    PHP Code:
      //test.php
      <?php
         $num 
    2;
          echo 
    $num*8;
       
    ?>
    Code Ruby:
      #in a view
      <% command = 'php test.php' %>
      <%= `#{command}` %>


    weird.. maybe if you post the contents of your php file?
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  3. #3
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP file works fine when I go straight to him with browser. It looks like:
    Code PHP:
      <?php
          echo "test";
       ?>

    May be there is some problem with configs? Do I need some sort of changing default options?
    http://www.ebookspirate.com - one page ebook aggregator


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
  •