acts_as_list | An ActiveRecord plugin for managing lists | Application Framework library
kandi X-RAY | acts_as_list Summary
kandi X-RAY | acts_as_list Summary
This acts_as extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a position column defined as an integer on the mapped database table.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of acts_as_list
acts_as_list Key Features
acts_as_list Examples and Code Snippets
Community Discussions
Trending Discussions on acts_as_list
QUESTION
I've seen a lot of tutorials around using Rails + SortableJS and updating the position of an object via Ajax - however, I'm using SortableJS inside a Rails form with hidden fields that contain the "position" attribute.
How can I update all of the elements of a Sortable group after one has been moved?
...ANSWER
Answered 2021-Dec-01 at 23:30In my experience, the gem act_as_list
—which you are already using—does what you need: Automatically updating the records.
For instance, in irb
, using a Message
model and destroying one record:
QUESTION
I have seen How to change a nullable column to not nullable in a Rails migration? for the problem of adding a non-nullable column to an existing database table with existing records. As such, I am thinking of doing this to add position sortability to the model using acts_as_list:
...ANSWER
Answered 2021-Aug-21 at 12:41class AddPositionToArticles < ActiveRecord::Migration[6.1]
def change
add_column :articles, :position, :integer
User.find_each do |user|
user.articles.order(created_at: :asc).find_each.with_index do |article, index|
article.update_columns(position: index)
end
end
change_column :articles, :position, :integer, null: false
end
end
QUESTION
I am trying to setup a project that uses rails 2.3.2. In my Gemfile I have gem "rails", "2.3.2"
. Running bundle install
outputs Using rails 2.3.2
. When I try to run any rails commands, in this case rails s
I get a load error.
ANSWER
Answered 2020-Dec-23 at 19:34In Rails 2.3.x the command to start the server is
QUESTION
Hi All I have a little app that takes an address on the stop model and geo codes it via geocoder gem
...ANSWER
Answered 2020-Aug-03 at 02:41You can access the next item in the list with:
QUESTION
I'm running Rails 6.0.3.2 and I want to render a partial passing a local variable to another controller view:
My routes:
...ANSWER
Answered 2020-Jul-31 at 18:09The rails way to do this is just to create a partial for a single record:
QUESTION
I'm trying to deploy my Rails 5.0 on heroku after a bundle update. I'm blocked by an issue on assets:precompile
...ANSWER
Answered 2020-Jun-30 at 09:08Thanks to @Les Nightingill, I found the issue.
It was not directly linked to assets generation, but the probleme was indicated at the first error line in the logs :
QUESTION
I've been searching for a day and a half for a solution.
I've got several tables (Categories) that allow the user to drag and drop each row (Item) to reorder the position of each item on that table (Category). I'm using SortableJS to handle the drag and drop, and I have it so that reordering within the same Category works.
On my backend I've got a Rails API that uses Jbuilder to return JSON, and am using the acts_as_list gem to handle the positions for me.
I'm having issues figuring out how to handle the reorder when I drag an Item from Category A to Category B. I believe the issue lies in the controller action and my inability to come up with a solution to receive updates for multiple categories, and then return the updated category's positions with Jbuilder. Some help would be greatly appreciated!
ItemsList.vue
...ANSWER
Answered 2020-Apr-01 at 04:32acts_as_list
allows you to set the new scope parameter and position of a list item, then just save the item and the item will be moved out of the old scope and into the new scope at the position you desire automatically (using after_save
callbacks).
In this regard, you should be able to just do that, then freshly fetch the items in each of your two scopes and return them to your front end for updating your display.
QUESTION
I have a fairly large question that I've been unable to resolve after a full day of reading articles, documentation and other Stack questions. At this point it's just messing with my mind!
I have an app that is Vue/Vuetify on the frontend with a data-table that I want to be able to reorder with sortablejs. On the backend, I have a Rails API that I'd like to use the acts_as_list gem to handle reordering for me.
Ideally I'd be able to call something like Category.first.items.last.move_higher
, however because I have a join model I'm having to put acts_as_list
and the position column on the join model instead of the Item model. Is there a better way to arrange this?
category.rb
...ANSWER
Answered 2020-Mar-25 at 05:51With that structure you'll definitely need to reorder by calling methods on the join model. You can however use the Rails delegate
class method to delegate reordering methods to the join model if you like:
https://api.rubyonrails.org/classes/Module.html#method-i-delegate
All of this assumes that you need items
and categories
to have a has_and_belongs_to_many
type relationship.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install acts_as_list
If you specify add_new_at: :top, new items will be added to the top of the list like always. But now, if you specify a position at insert time: .create(position: 3), the position will be respected. In this example, the item will end up at position 3 and will move other items further down the list. Before 0.8.0 the position would be ignored and the item would still be added to the top of the list. #220
acts_as_list now copes with disparate position integers (i.e. gaps between the numbers). There has been a change in behaviour for the higher_items method. It now returns items with the first item in the collection being the closest item to the reference item, and the last item in the collection being the furthest from the reference item (a.k.a. the first item in the list). #223
Or, from the command line:.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page