Giter VIP home page Giter VIP logo

acts_as_list's Introduction

Welcome to Rails

What's Rails?

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers: Model, View, and Controller, each with a specific responsibility.

Model layer

The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.

View layer

The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (ERB files). Views are typically rendered to generate a controller response or to generate the body of an email. In Rails, View generation is handled by Action View.

Controller layer

The Controller layer is responsible for handling incoming HTTP requests and providing a suitable response. Usually, this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and manipulate models, and render view templates in order to generate the appropriate HTTP response. In Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and controller classes are derived from ActionController::Base. Action Dispatch and Action Controller are bundled together in Action Pack.

Frameworks and libraries

Active Record, Active Model, Action Pack, and Action View can each be used independently outside Rails.

In addition to that, Rails also comes with:

  • Action Mailer, a library to generate and send emails
  • Action Mailbox, a library to receive emails within a Rails application
  • Active Job, a framework for declaring jobs and making them run on a variety of queuing backends
  • Action Cable, a framework to integrate WebSockets with a Rails application
  • Active Storage, a library to attach cloud and local files to Rails applications
  • Action Text, a library to handle rich text content
  • Active Support, a collection of utility classes and standard library extensions that are useful for Rails, and may also be used independently outside Rails

Getting Started

  1. Install Rails at the command prompt if you haven't yet:

    $ gem install rails
  2. At the command prompt, create a new Rails application:

    $ rails new myapp

    where "myapp" is the application name.

  3. Change directory to myapp and start the web server:

    $ cd myapp
    $ bin/rails server

    Run with --help or -h for options.

  4. Go to http://localhost:3000 and you'll see the Rails bootscreen with your Rails and Ruby versions.

  5. Follow the guidelines to start developing your application. You may find the following resources handy:

Contributing

We encourage you to contribute to Ruby on Rails! Please check out the Contributing to Ruby on Rails guide for guidelines about how to proceed. Join us!

Trying to report a possible security vulnerability in Rails? Please check out our security policy for guidelines about how to proceed.

Everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails code of conduct.

License

Ruby on Rails is released under the MIT License.

acts_as_list's People

Contributors

dhh avatar jeremy avatar mkdynamic avatar nzkoz avatar pixeltrix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

acts_as_list's Issues

position column is not incremented with Rails v3.0.2

I am using this plugin for several months already without problems in a Rails 3 app.
Now I updated from Rails 3.0.1 to 3.0.2 and suddenly the position column is not incremented beyond 2... meaning I have the following:

class Question < ActiveRecord::Base
  has_many   :answers
end

class Answer < ActiveRecord::Base
  belongs_to :question

  acts_as_list :scope => :question
end

My Answer model has a position column. When I create X answers for a question, I expect the positions to be 1, 2, 3, and 4.
With Rails 3.0.2 they are 1, 2, 2, and 2.
I tried running the tests included in the plugin locally and all passed, even with AR 3.0.3.
If anyone has a pointer to what might be the problem, I could investigate further.

Intermittently causes segfaults?

During cucumber tests, "[BUG] Segmentation fault" exceptions occurred when Rails loaded models with acts_as_list. I don't know if this was directly caused by acts_as_list, but removing it solved the issue for me.

when position is null all new items get inserted in position 1

I'm using 'remove_from_list' and a deleted_at attribute to remove items from list. The problem is that when creating a new record, if there are other records in the list with position of null, all new records get set to position 1. A workaround I've used is to set a default scope of :conditions => (:position ^ nil), but it seems to me at least, that the private method 'bottom_item' should have a default condition of position not nil.

#Insert_at(pos) inserts at wrong position when moving down

If find this an unexpected result from the #insert_at(pos) method:

Suppose you have:
1 A
2 B
3 C
4 D
5 E
6 F
7 G

And you move E to position 3 (before C) by #insert_at(3) the result will be as expected:
1 A
2 B
3 E
4 C
5 D
6 F
7 G

But now - starting all over - you move C to position 6 (before F), the result will be unexpected:
1 A
2 B
3 D
4 E
5 F
6 C
7 G

Technically, yes C has arrived on position 6, but NOT before 'F' as meant to be from a sorting point of view.

I consider this an issue. One way to solve it, is by adding a new method #move_to(pos) ?

acts_as_list does not play well with PostgreSQL and string scope name

PostgreSQL does not work with:
acts_as_list :scope => 'article_section_id', :column => 'sort_order'

When I run:
ArticleSection.find(1234).articles.create(title: "Test1")

It results in following error: ActiveRecord::StatementInvalid: PG::Error: ERROR: argument of WHERE must be type boolean, not type integer

because this SQL being executed:
SELECT "articles".* FROM "articles" WHERE (article_section_id) ORDER BY articles.sort_order DESC LIMIT 1

I was able to fix it basded on very old blog post: http://www.mattmccray.com/archive/2006/07/19/Comatose_and_PostgreSQL

All that I had to do was to change string names to symbols:
acts_as_list scope: :article_section_id, column: :sort_order

I report it since it looks like bug to me.

Remove use of update_attribute

Calling move_to_bottom causes the following warning:

DEPRECATION WARNING: update_attribute is deprecated and will be removed in Rails 4. If you want to skip mass-assignment protection, callbacks, and modifying updated_at, use update_column. If you do want those things, use update_attributes.

No column quoting

Fails because no quoting for column name in SQL commands.

Example:
acts_as_list :column => :order
and other reserved for SQL words.

Duplicates created when using accepts_nested_attributes_for

Duplicates are created if the child_attributes hash is set. Note that this occurs without even saving the model. Using the example in the README, if you include accepts_nested_attributes_for :todo_items and in a console wrote todo_list.todo_items_attributes = {"1" => { "position" => "1" } } you'd see the duplicate with todo_list.todo_items.

Usage with abstract classes

When acts_as_list is used on an abstract class, which has multiple subclasses, in some cases the plugin tries to get the order of the items in the abstract class.

This of course fails (the table cannot be found).

My solution was to add a check for this:

def acts_as_list(options = {})
    return if abstract_class
    ...

Graph like behaviour

I can store a relation that is a graph in fact. Is it expected? I think it should throw an exception when it recycling. Here is the test (please note that this test passes; however i am expecting it to fail):

category = Category.new
category.name="Parent"
category.save
child = category.children.create("name" => "child_1")
child.children = [category]
assert category.save
loadedChild = Category.find_by_name("child_1")
assert_equal "Parent", loadedChild.parent.name
assert_equal "Parent", loadedChild.children[0].name

When updating the "scope" attribute, the element is not "added" to the current list

Hi all
Models (Rails 3 application):
class NetworkService < ActiveRecord::Base
has_many :network_classes, :foreign_key => "network_id", :order => :position
end
class NetworkClass < ActiveRecord::Base
belongs_to :class_definition, :foreign_key => "class_id"
belongs_to :network_service, :foreign_key => "network_id"
acts_as_list :scope => :network_id
validates_presence_of :class_id, :network_id
attr_accessible :class_id, :network_id
end

Case:

  • when I create an element in NetworkClass, no problem it goes straight at the end of the current list.
  • when I update the "network_id" attribute which holds the "scope", the record is saved with a "position" set to 1, no matter if there are already records with the same "network_id". I would expect that the "position" of the updated record is set to the (last position + 1) of the list corresponding to the new "network_id" value. You then end up with multiple records with the same position in the list.
  • note: the NetworkClass "belongs to" another "class_definition" table, but not concerned with the list (I guess)

Many thanks for the gem anyway

Optimistic locking not being honoured

Any list update operation that uses update_all (decrement_positions_on_higher_items, decrement_positions_on_lower_items, increment_positions_on_higher_items, increment_positions_on_lower_items, increment_positions_on_all_items) is not updating the locking_column which can cause concurrency problems when the list can be edited by multiple users simultaneously.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.