mardi 9 février 2021

Retrieve JSON from SQLite with Ruby on rails

I am trying to save the error_text and the error_code to the sqLite table in a json format. However When trying to retrieve the value, I am facing errors and could solve it. I am using the below code snippet to get the error_text from the table

<td id="generate_<%= u[:employee_id] %>">
      <% if nh.ad_status[:error_code] == 4444 %>
        Creating...
      <% else %>
        <%= link_to 'Generate', api_adam_account_generate_path(employee_id: u[:employee_id]), remote: true, id: "link_#{u[:employee_id]}" %>
          <% if nh&.ad_status.blank? %>
            <span id="msg_<%= u[:employee_id] %>"></span>
          <% else %>
            <span id="msg_<%= u[:employee_id] %>"> <%= nh&.ad_status[:error_text] %></span>
          <% end %>
      <% end %>
    </td>

And the below code I am using to update the json column in the table.

Newhire.where(employee_id: eid_).update(ad_status: { error_code: 4444, error_text: "AD Create"})

I can retrieve the entire json from table using the below code.

Newhire.where(employee_id: 2863020).pluck(:ad_status)

However, I only need to retrieve the error_code alone from the json Can anyone help me in solving this issue? Thanks in Advance

Aucun commentaire:

Enregistrer un commentaire