Ruby and PHP working together

To anyone who has work with Ruby on Rails and LAMP(linux,apache,mysql,php) arch.

I got this new web project where I was planning using LAMP for the front-end and back-end and using ruby code for other server process/tasks.

I try looking in forums but haven’t found much since this is uncommon, but in your experience is this good or bad, the pros and cons.

If it has been succesfully implemented or have any example, let me know. Would you rather using just one or both or which one in what case.

Thanks in advance!

Source: stackoverflow-php

In Rails, how do I query my database from JavaScript so that I can fill in a textbox?

I have a view that uses the select method in Ruby on Rails to return the following code:

    <select class="form-control" name="xyz" id="food_id">
    <option value="1">Peach</option>
    <option value="2">Apple</option>
    <option value="3">Orange</option>

To pass this information over to the JavaScript file, I am basically using a link_to method in my view, such as the following:

<%= link_to "Import text", "#/", :onclick => "fillTextBox()" %>

In the JS file, how can I basically get the name and description of whatever value is selected in the dropdown? This is as far as I’ve gotten before I got confused:

function fillTextBox(){
    var dropdown = document.getElementById('food_id');
    var foodID = dropdown[dropdown.selectedIndex].value;

I need to do something like:

var foodName = Food.find(foodID).name;
var foodDescription = Food.find(foodID).description;

Is this possible? The rest of the JS function would basically fill in a textbox using foodName and foodDescription, but I first need to be able to query the database for this information in the first place.

Source: stackoverflow-javascript

How to trigger rails post method from file (using faye)

so i am using faye pub-sub in my application, publish is happening from different application, in my faye.js i have written ajax post method for rails. now if 5 pages of my application is opened in browser, faye.js is loaded 5 times and post method is called 5 times. if not a single page is opened, post method wont work even once. however i am receiving published data in faye server. so is there a way of calling rails post method in file when i use callback method.
This is my

require 'faye'

require File.expand_path('../config/initializers/faye_token.rb', __FILE__)

Faye.logger =

class ServerAuth
  def incoming(message, callback)
    if message['channel'] !~ %r{^/meta/}
      if message['ext']['auth_token'] != ENV['FAYE_TOKEN']
        message['error'] = 'Invalid authentication token'

  # IMPORTANT: clear out the auth token so it is not leaked to the client
  def outgoing(message, callback)
    if message['ext'] && message['ext']['auth_token']
      message['ext'] = {} 

$bayeux = => '/faye', :timeout => 25)


run $bayeux

and my faye.js

$(function() {
  var faye = new Faye.Client('http://localhost:9292/faye');
faye.subscribe("/functional", function(data) {

Source: stackoverflow-javascript

Choosing programming platform/language: MQTT, DB & Webserver

I want to write a server application which is able to subscribe to an MQTT broker, store the data it receives in a database like MySQL and also present the data in a webpage, but I don’t know what the best setup would be for this.

Options I thought of:

  1. Separate programs for all steps: One which handles the connection between the MQTT broker in Java or something and another framework in a framework I’m familiar with like RoR or PHP.

  2. A complete package written in NodeJS which does everything self contained.

Which of these is the most efficient and/or flexible approach, or am I completely missing the mark and do you have a better solution?

Source: stackoverflow-php