title: ruby on rails I need to build an object from api data
body: <p>I want to create an object from data API. At first, the user will have to enter his immaticulation number. Once registration typed him return the following data in the view show</p>
  <h1>vehicles_controller:</h1>
  <pre><code>   @vehicle = Vehicle.new
     @vehicles = []
      vehicle_number = params['immatricule'].capitalize
      vehicles.each do |vehicule|
      data_api = CarRegistrationFrance.Lookup(#{&quot;vehicle_number&quot;},&quot;username&quot;,&quot;password&quot;)
  
  Api_data response:
  
   =&gt; {&quot;Description&quot;=&gt;&quot;RENAULT CLIO IV&quot;, &quot;RegistrationYear&quot;=&gt;&quot;2017&quot;, &quot;CarMake&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;RENAULT&quot;}, &quot;CarModel&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;CLIO IV&quot;}, &quot;EngineSize&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;4&quot;}, &quot;FuelType&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;DIESEL&quot;}, &quot;MakeDescription&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;RENAULT&quot;}, &quot;ModelDescription&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;CLIO IV&quot;}, &quot;Immobiliser&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;&quot;}, &quot;IndicativeValue&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;0}, &quot;DriverSide&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;&quot;}, &quot;BodyStyle&quot;=&gt;{&quot;CurrentTextValue&quot;=&gt;&quot;BERLINE 5 PORTES&quot;}, &quot;RegistrationDate&quot;=&gt;&quot;2017-10-30&quot;,&quot;ExtendedData&quot;=&gt;{&quot;anneeSortie&quot;=&gt;&quot;2017&quot;, &quot;boiteDeVitesse&quot;=&gt;&quot;&quot;, &quot;carburantVersion&quot;=&gt;&quot;D&quot;, &quot;carrosserieVersion&quot;=&gt;&quot;&quot;, &quot;classeSra&quot;=&gt;&quot;K&quot;, &quot;libVersion&quot;=&gt;&quot;1.5 DCI 90 EDITION ONE EDC&quot;, &quot;libelleModele&quot;=&gt;&quot;CLIO IV&quot;, &quot;marque&quot;=&gt;&quot;RE&quot;, &quot;modele&quot;=&gt;&quot;88&quot;, &quot;produit&quot;=&gt;&quot;&quot;, &quot;puissance&quot;=&gt;&quot;4&quot;, &quot;version&quot;=&gt;&quot;&quot;, &quot;cleCarrosserie&quot;=&gt;&quot;&quot;, &quot;groupeSra&quot;=&gt;&quot;30&quot;, &quot;nbPlace&quot;=&gt;&quot;5&quot;, &quot;datePremiereMiseCirculation&quot;=&gt;&quot;30102017&quot;, &quot;questionBatterie&quot;=&gt;&quot;&quot;, &quot;electrique&quot;=&gt;&quot;&quot;, &quot;genre&quot;=&gt;&quot;&quot;, &quot;typeVehicule&quot;=&gt;&quot;&quot;, &quot;numSerieMoteur&quot;=&gt;&quot;VF15RBJ0D58888591&quot;, &quot;valeurANeufSRA&quot;=&gt;&quot;&quot;, &quot;niveauRisqueVol&quot;=&gt;&quot;&quot;, &quot;protectionConstructeur&quot;=&gt;&quot;&quot;, &quot;puissanceDyn&quot;=&gt;&quot;&quot;, &quot;segmentVeh&quot;=&gt;&quot;&quot;}} 
      @vehicles &lt;&lt; data_api
      vehicle.description =&gt; data_api[&quot;Description&quot;]
      vehicle.annee =&gt; data_api[&quot;RegistrationYear&quot;]
  
  
      def vehicle_params
    params.require(:voiture).permit(:immatricule, :description, :annee)
  end
  </code></pre>
  <p>Once the user enters his registration numbers I want to join</p>
  <pre><code>data_api [&quot;Description&quot;] &lt;&lt; vehicle [&quot;description&quot;]
  </code></pre>
  <p>attach the data to the attribute of the vehicle object</p>
  <pre><code>data_api [&quot;RegistrationYear&quot;] &lt;&lt; vehicle [&quot;year&quot;]
  </code></pre>
  <p>/user[:id]/vehicle/new its an example</p>
  <pre><code>&lt;%= form_tag(&quot;/vehicle&quot;, method: &quot;post&quot;) do %&gt;
    &lt;%= label_tag(:immatricule, &quot;&quot;) %&gt;
    &lt;%= text_field_tag(:immatricule) %&gt;
    &lt;%= submit_tag(&quot;create&quot;) %&gt;
  </code></pre>
  <p>/user[:id]/vehicle/show it an example</p>
  <pre><code>&lt;%= @vehicle.api_data[&quot;Description&quot;] %&gt;
  &lt;%= @vehicle.api_data[&quot;RegistrationYear&quot;] %&gt;
  </code></pre>
  <ol>
  <li>enter your immatricule number</li>
  <li>post immatricule of vehicle user to api_data</li>
  <li>create objet vehicle from response api_data</li>
  <li>render show view</li>
  </ol>
  <p>I've tried several operations but I can not find a solution.</p>