Closed Lubard closed 7 years ago
@Lubard Let me have a look at your model and javascript.
@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
@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
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 :(
@Lubard Any errors in the browser or the server console? I can't reproduce the problem...
@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 > <
Can you push your app to Github?
I also get the 422 error, and the logs say "ActiveRecord::RecordInvalid - Validation failed: Name has already been taken"
@kramersharp
I think you have a duplicated name
value in your model, and which causes the validation error.
Closable?
Yeah, the bug has been fixed. I'll close this issue in a moment.
` <% @staffs = Staff.order(:staff_order) %>