igorkasyanchuk / rails_db

Rails Database Viewer and SQL Query Runner
https://www.railsjazz.com/
MIT License
1.46k stars 111 forks source link

Editing always set deleted_at date, so record becomes deleted when using soft deletes #89

Closed ignaciosiri closed 6 years ago

ignaciosiri commented 6 years ago

Hi! Love this gem, but i'm using paranoia to handle soft deletes, so when i try to edit a record, even if i don't set a date for deleted_at field, it comes preset on the edit form, making the record "deleted" to the app.

Am I misunderstanding something?

It would be nice to handle nil dates, so it preserves the value. Maybe a datepicker instead of rails's input date fields?

Hope to hear your thoughts about this and discuss possible solutions!

Cheers!

capture

igorkasyanchuk commented 6 years ago

thanks for reporting an issue :) a fix is coming soon, already in master. waiting for specs

ignaciosiri commented 6 years ago

Excellent, thanks!

igorkasyanchuk commented 6 years ago

try rails_db-2.0.1.gem

ignaciosiri commented 6 years ago

Figured out I can't try newers versions because im running rails 4.1.8 in this project 😭 I'll try next with new ones :) Thanks, super fast fix!!

igorkasyanchuk commented 6 years ago

I see ... okay then I suggest to make a fork and do this change in your fork:

https://github.com/igorkasyanchuk/rails_db/blob/master/app/views/rails_db/tables/_edit.html.erb#L11-L19

and use it

igorkasyanchuk commented 6 years ago

I don't plan to add support for paranoia for older rails, at least not now, maybe you can add support for it and make a PR from your fork

ignaciosiri commented 6 years ago

Ok, i'll give it a try! Thanks for ur time and support!

ignaciosiri commented 6 years ago

Hi @igorkasyanchuk, I've made the changes you mentioned (locally in the gem's file) and it works like a charm. I'm not very familiar with forks/PRs/etc specially to target an older version of the gem. If you want me to do something to merge the code im here to help, but need some guidelines haha.

Here's the final _edit.html.erb code:

<a class="close-reveal-modal" aria-label="Close">&#215;</a>

<h2 id="modalTitle">Edit</h2>

<%= simple_form_for @record, as: 'record', url: table_update_path(@table, pk_id: @record[@table.primary_key]), remote: true, method: :put, html: {class: 'vertical_form'} do |form| %>
    <div class='scrollable_form'>
      <% @record.class.columns.each do |column| %>
        <% name = column.name %>
        <% next if name == @table.primary_key %>

        <% options = { label: name } %>
        <% options[:include_blank] = true if column.type.to_s =~ /time|date/ %>
        <% if column.type.to_s =~ /text/ %>
          <% options[:input_html] = {} %>
          <% options[:input_html][:rows] = 4 %>
          <% options[:input_html][:cols] = 80 %>
        <% end %>

        <%= form.input name, options %>
      <% end %>
    </div>
    <%= form.submit 'SAVE', class: 'button small' %>
    <a class='close' onclick="$('#system_modal').foundation('reveal', 'close');$">Close</a>
<% end %>

<span class="radius warning label">NOTE: Update will happen without any validations.</span>
igorkasyanchuk commented 6 years ago

push your code to github and create a PR for rails_4_x branch. https://help.github.com/articles/creating-a-pull-request/

ignaciosiri commented 6 years ago

Perfect! I've just created the PR, hope it helped! Have a great day! :)