Skip to content

Instantly share code, notes, and snippets.

@stream7
stream7 / README.markdown
Created August 13, 2011 11:33 — forked from ariera/README.markdown
Nestable, sortable and dragable categories

Nestable, sortable and dragable categories:

In the project I'm working on we wanted to have a Category model which we wanted to be nestable. But we also liked the user to have a draggable interface to manage and rearrange the order of his categories. So we chose awesome_nested_set for the model and jQuery.nestedSortable for the UI.

It took me some time to arrange things to work properly so I wanted to share my work in case it helps anybody.

Before beginning

you might want to take a look at a demo app

  1. go to: http://awesomenestedsortable.heroku.com/groups/
  2. click in show of any group
@stream7
stream7 / migration_integer_limit_option
Created July 7, 2011 14:09
Rails migrations integer :limit option
literally always have to look up the meaning of :limit in migrations when it comes to integer values. Here's an overview. Now let's memorise it (oh, this works for MySQL, other databases may work differently):
:limit Numeric Type Column Size Max value
1 tinyint 1 byte 127
2 smallint 2 bytes 32767
3 mediumint 3 byte 8388607
nil, 4, 11 int(11) 4 byte 2147483647
5..8 bigint 8 byte 9223372036854775807
Note: by default MySQL uses signed integers and Rails has no way (that I know of) to change this behaviour. Subsequently, the max. values noted are for signed integers.
@stream7
stream7 / view_sql_in_rails_console
Created July 5, 2011 13:24
SQL logs from activerecord in rails console
For Rails 2:
ActiveRecord::Base.connection.instance_variable_set :@logger, Logger.new(STDOUT)
For Rails 3:
ActiveRecord::Base.logger = Logger.new(STDOUT)
taken form http://stackoverflow.com/questions/1344232/how-can-i-see-the-sql-that-will-be-generated-by-a-given-activerecord-query-in-rub