I
I
isd12272016-03-01 18:21:34
Ruby on Rails
isd1227, 2016-03-01 18:21:34

How do I write data to JSON on RoR?

There is a task to write data either from an input (located outside the form (is it possible to do this without a form at all?)), or from uploaded pictures (you need to get the name + extension from them)
How to implement this on rails? I just started to study, I know that this can be done in php, but I want to learn how to work with rails, and the project has already started to do on it, advise me to read something on the topic of my question, if you drop the necessary links, it will be great in general. Something
like this this is done in php, but you need an analogue on rails

<?
session_start();
  require_once("include/db_connect.php");
?>

<?
if($_SERVER["REQUEST_METHOD"] == "POST"){
  $id=$_SESSION['id'];
  $name_marker=$_POST['name_marker'];
  $description_marker=$_POST['description_marker'];
  $sh=$_POST['sh'];
  $dg=$_POST['dg'];
  $rt=$_POST['rt'];
  
  if(!empty($_SESSION['login_suc'])){
    $sql="INSERT INTO 
    `markers`(`id_marker`, `id_user`, `title`, `desc`, `reit`, `sh`, `dg`) VALUES
     ('','".$id."','".$name_marker."','".$description_marker."','".$rt."','".$sh."','".$dg."')";
      $stmt=$dbh->prepare($sql);
      $stmt->execute();
      echo "Вы добавили маркер";
    $sql="SELECT * FROM markers";
        $query=$dbh->query($sql);
        foreach ($query=$dbh->query($sql) as $row) 
        {
          $array[]=$rows[] = array(
            "name"=>$row["title"],
          "info"=>$row["desc"],
          "reit"=>$row["reit"],
          "lat"=>$row["sh"],
          "lng"=>$row["dg"]
         );
        }
       $file='places.json';
       $a='{"placesData":';
       $a=$a.json_encode($rows).'}';
       file_put_contents($file, $a);
  }else{
    echo "Вам необходимо авторизироваться";
  }
}
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2016-03-01
@isd1227

To be honest, I hardly understand what exactly is needed, but on a hunch I will suggest reading this rusrails.ru/api-app

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question