- We design and build extraordinary applications for companies looking to make the next great idea a reality.
- learn more
Mass Assigning Inheritance Column Values for ActiveRecord STI with Rails
One of the security features in Rails is to prevent mass assigning values for certain columns (when passing a hash to #new, #attributes=, and #update_attributes). This is to ensure that a malicious user can't exploit the system by passing in values for certain attributes you really don't want them to change.
In Rails 2.1, one of the attributes that will always be protected from mass assignment is the inheritance_column. In most cases, protecting inheritance_column; is desired because we don't want (for example) someone to change their user type by specifying type = 'Admin' when posting a form. Despite this, there are some cases where we do want to allow the user to specify the type.
However, even if we specify #attr_accessible on the inheritance_column, we will not be able to mass assign a value to it. Rails will not allow it unless we put in a little hack to work around this feature.
Topics: activerecord, Ruby on Rails, STI
How to use will_paginate with non-ActiveRecord collection/array
will_paginate is very well designed plugin. Besides ActiveRecord object integration, it can integrate with array and any collection that you may have. The README.rdoc (in version 2.2.2) and wiki clearly and concisely document how to use it with ActiveRecord objects. I recently needed to use it for a collection outside of activerecord and here is how I did it.
Continue reading »
Topics: activerecord, pagination, Ruby on Rails, will_paginate
About Pathfinder
Recent
- Bandwidth profiling Flex projects and more with Charles
- iPhone SDK: UIViewController Testing & TDD
- Icons are evil; so are menus - unless you do them right
- The Truth About Designing For Security
- GWT, Gadgets and OpenSocial, Part 2
- Has Many has_many: A Refactoring Story
- The Hidden Power of Canvas
- Review of fixture_replacement2 plugin
- Chess Game Viewer in GWT
- From JSP to Ruby on Rails: First thoughts on front-end coding conventions
Archives
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006


