Forum: Ruby on Rails Speakin of the Devil..

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
224b787861d66cc06fa539df14672763?d=identicon&s=25 Dominic Son (Guest)
on 2006-06-06 10:56
Hi.

How can one embed PHP into their rhtml files (located in the views
folder?

I'd like to use those JD library graphical plugs that use PHP...

I've already added .rhtml to the php extension in apache's httpConfig..

Insights or the truth would be appriciated.

Dominic Son
6f7c877de704c7cc03c8a3b2dc52df92?d=identicon&s=25 Carmen --- (carmen)
on 2006-06-06 12:02
> I've already added .rhtml to the php extension in apache's httpConfig..

what did you think this would do? besides confuse apache even more??

> How can one embed PHP into their rhtml files (located in the views
> folder?

your best bet is to not embed php in a rhtml file, but to embed it in a
php file, and designate a subdir to use the php interpreter. eg, with
lighttpd:

server.document-root     = "/var/www/railsapp/public/"
server.error-handler-404 = "/dispatch.fcgi"
fastcgi.server = ( ".fcgi" =>
  ( "localhost" =>
      (
        "min-procs" => 1,
        "max-procs" => 1,
        "socket"    => "/var/www/railsapp/log/fcgi.socket",
        "bin-path"  => "/var/www/railsapp/public/dispatch.fcgi",
        "bin-environment" => ( "RAILS_ENV" => "development" )
      )
  )
)

$HTTP["url"] =~ "^/php" {
server.document-root     = "/var/www/php/"
alias.url = ( "/php/" => "/var/www/php/" )
fastcgi.server = ( ".php" =>
  ( "localhost" =>
      (
      "bin-path" => "/usr/bin/php-cgi -c /etc/php.ini",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "1",
"PHP_FCGI_MAX_REQUESTS" => "32"
),
        "socket"    => "/tmp/php.socket"
      )
  )
)
}

or you just want to be messy and throw your php files in public/ you
could remove the $HTTP["url"] =~ "^/php" { and the two lines below it.
im sure apache can do all this..i switched to lighttpd for the concise
and simple configuration. the better performance is just gravy..
6f7c877de704c7cc03c8a3b2dc52df92?d=identicon&s=25 Carmen --- (carmen)
on 2006-06-06 12:05
> How can one embed PHP into their rhtml files (located in the views
> folder?

popen() the php interpreter in your view, and display the results
inline. but thats pretty nasty if you ask me..
224b787861d66cc06fa539df14672763?d=identicon&s=25 Dominic Son (Guest)
on 2006-06-06 22:54
It is quite nasty. And if nasty, violates Ruby philosophy.

So beware Ruby writers, it's possible to say if you embed in Ruby, you
may not be programming in Ruby anymore.

; )

Dominic Son

carmen  wrote:
>> How can one embed PHP into their rhtml files (located in the views
>> folder?
>
> popen() the php interpreter in your view, and display the results
> inline. but thats pretty nasty if you ask me..
8c43ed7f065406bf171c0f3eb32cf615?d=identicon&s=25 Zed Shaw (Guest)
on 2006-06-07 12:04
(Received via mailing list)
On Tue, 2006-06-06 at 12:05 +0200, carmen wrote:
> > How can one embed PHP into their rhtml files (located in the views
> > folder?
>
> popen() the php interpreter in your view, and display the results
> inline. but thats pretty nasty if you ask me..
>

No, don't do this.  popen() in ruby has very weird issues and will cause
you mountains of problems.  The #1, #2, and #3 thing that seems to cause
Rails apps to slow or stop is popen.


--
Zed A. Shaw
http://www.zedshaw.com/
http://mongrel.rubyforge.org/
55428cbf149e35dd4b65f1d019d04139?d=identicon&s=25 Matt Palmer (Guest)
on 2006-06-07 12:24
(Received via mailing list)
On Tue, Jun 06, 2006 at 10:56:10AM +0200, Dominic Son wrote:
> How can one embed PHP into their rhtml files (located in the views
> folder?
>
> I'd like to use those JD library graphical plugs that use PHP...
>
> I've already added .rhtml to the php extension in apache's httpConfig..

That's not going to work, as the rhtml file gets interpreted by the
Rails
dispatcher, not Apache.  The only thing I can think of is to invoke the
PHP
interpreter inside of Rails, but the resulting tentacles are your own
problem.

For image generation, though, you don't need to run PHP inside of Rails,
you
just need to point your image src= at the PHP script.  But I don't know
anything about these "JD library graphical plugs", so maybe you do need
PHP
inside your HTML.

- Matt
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2006-06-07 15:39
(Received via mailing list)
Put the php page in another folder as suggested above and use Ruby's
net/http library to make the request to your server. This allows yo
uto store this into a string which you can then parse and embed.

Or look for Ruby/Rails based solutions for your problem.
This topic is locked and can not be replied to.