Halaman

Rabu, 17 November 2010

[shared] Unsigned int support for migration

currently rails only allow signed int for migration, but for best practice it's better to use unsigned int for some cases

you can force migration to unsigned int by doing something like this

t.column :unsigned_value, "integer unsigned"


but that kinda ugly to see.
luckily rob anderton (thewebfellas.com) already created monkey patch to add unsigned support: http://thewebfellas.com/assets/2008/9/30/active_record_unsigned.rb

the patch will add :unsigned option in migration so you can do something like this:

t.integer :unsigned_value, :unsigned => true


furthermore the patch will make default table id and foreign key to unsigned int(11), but make sure to use t.references to create foreign key or simply use :unsigned => true

important things:


- for existing project this patch might break table relation because it will create unsigned int foreign key but the primary key might be signed int from old migration
- some plugin like role_requirement will generate migration that using t.integer for foreign key instead of t.references, you need to change this manually
- the patch will only change mysql adapter, so it will not work for other adapter

[shared] Rails migration integer limit

:limit Numeric Type Column Size Signed Max value Unsigned Max value
1 TINYINT(4) 1 byte 127 255
2 SMALLINT(6) 2 bytes 32767 65535
3 MEDIUMINT(9) 3 bytes 8388607 16777215
4 and others INT(11) 4 bytes 2147483647 4294967295
5..8 BIGINT(20) 8 bytes 9223372036854775807 18446744073709551615

Minggu, 14 November 2010

[shared] rails user role system

https://github.com/timcharper/role_requirement

installation:
- ruby script/generate roles Role User

installation will do:

  • Generates habtm table, creates role.rb with the habtm declaration. Adds declaration in user.rb (scans the code for "class User < ActiveRecord::Base", and puts the new code right after it.



  • Creates an admin user in users.yml, with a role named admin in roles.yml, including a fixture to demonstrate how to relate roles to users in roles_users.yml



  • Modify the user.rb (or corresponding user model) file, add the instance method has_role?



  • Generates RoleRequirementSystem against for the corresponding user model.



  • Generates a migration to make the necessary database changes



  • Scans ApplicationController, inserts the lines "include AuthenticatedSystem", and "include RoleRequirementSystem", if not already included.



  • Scans test_helper.rb and adds "includes RoleRequirementTestHelpers", if not already included.




Usage:
- add require_role "role_name" in controller, similar to before_filter

[shared] rails exception logger

https://github.com/defunkt/exception_logger

installation:
- ruby script/generate exception_migration
- rake db:migrate
- in application_controller.rb add
include ExceptionLoggable
rescue_from Exception, :with => :exception_handler

private

def exception_handler exception
log_exception exception
render "/500.html"
end


the default controller and view using prototype.js instead of jquery so i created my own controller view under admin namespace. the database pretty simple and similar to rails exception notification

for rails 3:
https://github.com/QuBiT/exception_logger

Rabu, 10 November 2010

kaspersky conflicting with tortoise svn

kaspersky, settings, exclusions, add:
- rules for the project folder
- trusted application for:
- - ..\system32\searchprotocolhost.exe
- - ..\system32\searchfilterhost.exe
- - ..\tortoisesvn\bin\tsvncache.exe
- - ..\tortoisesvn\bin\tortoiseproc.exe
- - ..\tortoisesvn\bin\tortoisemerge.exe

other possible cause:
win7 bug prior sp1: http://support.microsoft.com/kb/982927/en-us