In a model I needed to modify a getter to append a string if a certain attribute evaluated to true. This works great, until I needed to detect the uniqueness of the attribute against a column in the DB through the :uniqueness validator.
new_value = read_attribute(:label)
if self.something == true
new_label += 'Str'
When validating against the label’s uniqueness the validator will read the label attribute from my custom getter, thus, if a record in the DB has a label of ‘Test’, and our new record has a label of ‘Test’ and self.something evaluates to true, the validator will get ‘TestStr’ from the getter and compare the custom value against the DB. Based on this setup, no match would be found. Continue reading
When I first started writing in ruby I found myself needing to know the ruby method equivalents to specific PHP functions. These methods are widely used by myself for debugging and day to day checking of data types.
PHP’s die(‘message’) becomes
PHP’s get_class_methods() becomes
PHP’s in_array() becomes
The last few months have proved to be a tough time for myself. During the past few months I have finalised a divorce and clean break order, started a new position at an up and coming cloud service and moved into a new home. In turn, I haven’t had the chance to concentrate on YAPS.
While I thoroughly enjoy writing plugins and particularly the YAPS framework my heart currently lies with Ruby on Rails development, being that my job relies on it, and that I find it astoundingly enjoyable to code in.
Having a vast amount of ideas for small web apps that could be useful to many, further progressing YAPS, with the time required to manage and support the plugin framework will prohibit this. Thus, I have had to make the decision to discontinue the development. Continue reading
I was discussing with Pippin from PippinsPlugins about using his pretty cool, extremely light weight logging class for YAPS, by extending the core.
The conversation got me thinking about ways to inject methods into an already existing class without using experimental code and extensions for PHP, such as classkit and runkit.
For the past week I have been playing with ruby and of course, rails. My experience has been an absolute pleasure, I can’t quite express the joy I have in having the opportunity to learn, use and abuse ruby on rails.
Having come to experience ruby after 11 years with PHP and PHP alone as a server side language, the only frustration I have is learning new syntax. No, that’s not a fault of ruby’s, infact I find ruby to be an absolutely beautiful language to write in. Its so… English!
I haven’t posted in a little while, that’s because on the 05th I started a new role at a excellent startup, Skyscape Cloud, acting as their only web developer.
My main development skills lie with PHP, however my new role has given me an opportunity to broaden my development horizons with ruby, specifically rails.
This week I have spent a great deal of time working on the YAPS core, specifically a series of classes for forms, fields and validation.
The general concepts surrounding these classes is to allow for simple management of forms, fields and validation. Continue reading
If you are familiar with PHP you will know that strings can be contained within single quotes or double quotes. More often than not developers tend to always use double quotes, despite the context of the string.
While this is OK in principle, double quotes take more processing time than that of single quotes (despite being minimal). This is because PHP expects to find variables within double quoted strings and parse them. Continue reading
More often than not while writing in PHP, you will need to debug the code you have written and/or find out relevant information about classes. This tip outlines different debugging methods such as print_r, var_dump and error logging as well as useful class functions. Continue reading
Is the following error familiar to you?
Fatal error: Allowed memory size of XXX bytes exhausted
It is to me, and recently I’ve written an import script that reads the contents of 10 XML files. These files accumulate a total of 14.9MB in size. The XML files contain page content (A good 10,000), each page has references to images and PDFs which needed to be downloaded, stored on the filesystem in the same directory structure as well as imported into an asset manager, again in the same structure. Once the assets have been downloaded the script stores the contents of the XML files. Continue reading