Total Blog Views: 101
Blog Status: publish
Created By: rushabh_subodh Created at: 08-06-2021
As In the current Technology world Every one wants the dynamic feature in there website in day to dy use
So We will learn today
We Will Create a Sample App For the same
$ rails new DragDropApp
$ rails g scaffold Item title:string body:text
Note: The above command will create All the files required For Item Module(Model View Controller), Then Run Below Command
$ rails db:create db:migrate
Rails.application.routes.draw do
resources :items
root 'items#index'
end
Now The sample Application is ready Now You can Run $ rails s and check your application then add some sample Items
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'rails_sortable'
After Adding the Gem Run Bundle Install
$bundle install
//= require jquery
//= require jquery_ujs
//= require jquery-ui/widgets/sortable
//= require rails_sortable
class Item < ApplicationRecord
include RailsSortable::Model
set_sortable :sort
end
class ItemsController < ApplicationController
def index
@items = Item.order(:sort).all
end
end
<table>
<tbody class="sortable"> <!-- sortable target -->
<% @items.each_with_sortable_id do |item, sortable_id| %>
<tr id="<%= sortable_id %>"> <!-- Needs id tag on sorting elements -->
<td><%= item.title %></td>
<td><%= item.sort %></td>
<td><%= link_to 'Show', item %></td>
<td><%= link_to 'Edit', edit_item_path(item) %></td>
<td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
Update application.js
$(function() {
$('.sortable').railsSortable();
});Then start You rails application
$ rails s
we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.
© Copyright Shadbox. All Rights Reserved
Rate Blog :
Share on :
Do you have any blog suggestion? please click on the link