itmammoth / rails_sortable

Easy drag & drop sorting with persisting the arranged order for rails
MIT License
142 stars 37 forks source link

the result is not recorded #1

Closed Lubard closed 7 years ago

Lubard commented 7 years ago

` <% @staffs = Staff.order(:staff_order) %>

<% sortable_fetch(@staffs) do |staff, id_tag| %> <% end %>
<%= staff.nickname %> <%= staff.staff_order %>
` here's my code, and when I drag & drop the staff and flush, nothing changed... sort changed: ![screen shot 2017-04-10 at 1 00 16 pm](https://cloud.githubusercontent.com/assets/4156201/24844411/be9a54cc-1ded-11e7-83f1-61f3411cd605.png) Then Flush: ![screen shot 2017-04-10 at 1 00 38 pm](https://cloud.githubusercontent.com/assets/4156201/24844412/bed5999c-1ded-11e7-81a1-cf5531f974a0.png) is there anything I missed?
itmammoth commented 7 years ago

@Lubard Let me have a look at your model and javascript.

Lubard commented 7 years ago

@itmammoth Hi! The model as: ` class Staff < ActiveRecord::Base include RailsSortable::Model

has_many :customers
has_many :orders

has_many :staff_time_periods
has_one :default_average_period
has_one :default_start_date

# validates :email, unique: true

has_secure_password
set_sortable :staff_order`

and the page is like:

<% @staffs = Staff.active_sales_staff.order(:staff_order) %>
<table>
<tbody class="sortable">  <!-- sortable target -->
    <% sortable_fetch(@staffs) do |staff, id_tag| %>  <!-- RailsSortable helper -->
      <tr id="<%= id_tag %>">
        <td><%= staff.nickname %></td>
        <td><%= staff.staff_order %></td>
      </tr>
    <% end %>
  </tbody>
</table>

$(".sortable").railsSortable(); is the one and only js code in this page

itmammoth commented 7 years ago

@Lubard I found a bug in set_sortable method, and which has been fixed. Please try it again with the gem version 0.1.0. Thx

Lubard commented 7 years ago

Hi @itmammoth Sorry for the missing for last couple days... I tried both version 0.1.0 and 0.1.1, they were both failed to fix this :(

itmammoth commented 7 years ago

@Lubard Any errors in the browser or the server console? I can't reproduce the problem...

Lubard commented 7 years ago

@itmammoth Oh! I just found one:

[Error] Failed to load resource: the server responded with a status of 422 (Unprocessable Entity) (reorder, line 0)

after I dragged the item.

def parse_params

    klass_name = params.keys.first

    ids = params[klass_name].map {|id| id.to_i }

    [ klass_name.constantize, ids ]

  end

undefined method 'map' for "sortable":String for line 20 > <

itmammoth commented 7 years ago

Can you push your app to Github?

kramersharp commented 7 years ago

I also get the 422 error, and the logs say "ActiveRecord::RecordInvalid - Validation failed: Name has already been taken"

itmammoth commented 7 years ago

@kramersharp I think you have a duplicated name value in your model, and which causes the validation error.

scarroll32 commented 7 years ago

Closable?

itmammoth commented 7 years ago

Yeah, the bug has been fixed. I'll close this issue in a moment.