Service PHP in Rails

22 views
Skip to first unread message

Marco Dias

unread,
Jun 27, 2015, 3:51:29 PM6/27/15
to rubyonra...@googlegroups.com
I have a small PHP service that is being called in a JavaScript file by
AJAX :

$.ajax({
type: "GET",
url: "getDate.php",
dataType:"json",
data :{
fromDate:fromDate,
toDate:toDate
},
success: function(data) {
......
}
});

This service contains :


$fromDate = $_GET['fromDate'];
$toDate = $_GET['toDate'];
$fromDate=date_create($fromDate);
$fromdate =
date_format($fromDate,"Y-m-d")."T".date_format($fromDate,"H:i:s")."Z";
$fromdate = urlencode($fromdate);
$toDate=date_create($toDate);
$todate = date_format($toDate,"Y-m-d")."T23:00:00Z";
$todate = urlencode($todate);
$url =
"http://194.209.53.19:8086/query?db=Bellevue&q=select+*+from+measures+where+time%3E%3D%27".$fromdate."%27+and+time%3C%3D%27".$todate."%27";
$data = file_get_contents($url, false);
echo $data;

I need to use this in my Rails application. I was wondering if I could
put the .php file in a Rails folder, and simply call it. Or if there's a
way to do a similar service in Rails? And how do I write these 11 lines
in Rails ? I'm pretty new to Rails.

--
Posted via http://www.ruby-forum.com/.

Walter Lee Davis

unread,
Jun 27, 2015, 5:30:42 PM6/27/15
to rubyonra...@googlegroups.com
You'll have to configure a separate handler for it, in the Apache configuration (or whatever Web server you use). Rails runs Ruby natively, and the Rails router has no interest in or knowledge of PHP. It will happily serve any *static* files that you place in the app/public folder.

Walter

>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/034fe1d073c7f8b9dc3c7dc317cdd5d4%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Hassan Schroeder

unread,
Jun 27, 2015, 6:16:04 PM6/27/15
to rubyonrails-talk
On Sat, Jun 27, 2015 at 12:50 PM, Marco Dias <li...@ruby-forum.com> wrote:
> I have a small PHP service that is being called in a JavaScript file by AJAX :

> I need to use this in my Rails application. I was wondering if I could
> put the .php file in a Rails folder, and simply call it.

No.

> Or if there's a way to do a similar service in Rails?

Yes.

> And how do I write these 11 lines in Rails ? I'm pretty new to Rails.

This represents a pretty trivial exercise, so I'd recommend you tackle
it and post again if you have problems :-)

Good luck.
--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Colin Law

unread,
Jun 28, 2015, 4:05:23 AM6/28/15
to rubyonra...@googlegroups.com
On 27 June 2015 at 20:50, Marco Dias <li...@ruby-forum.com> wrote:
> And how do I write these 11 lines
> in Rails ? I'm pretty new to Rails.

I suggest you start by working right through a good tutorial such as
railstutorial.org (which is free to use online). That will show you
the basics of rails.

Colin
Reply all
Reply to author
Forward
0 new messages