<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description>29 Steps is a software development company using Ruby,Rails and HTML5.</description><title>29 Steps</title><generator>Tumblr (3.0; @29stepz-blog)</generator><link>http://blog.29steps.co.uk/</link><item><title>Testing API Web Calls in Elixir using meck</title><description>&lt;p&gt;Elixir is a powerful functional programming language with an equally powerful test suite call ExUnit. it is possible to write unit and high level integration specs while developing.&lt;/p&gt;
&lt;p&gt;As a Rubyist, one of the things that intrigued me was how do you test API calls as one could do in Ruby. I use WebMock a lot in Ruby tests - so is there something similar in Elixir / Erlang?&lt;/p&gt;
&lt;p&gt;In a recent elixir project, I needed to do something similar and while reading through the test code for HTTPoison, I noticed a library called &lt;a href="https://github.com/eproxus/meck" title="Meck" target="_blank"&gt;meck&lt;/a&gt; being used. Its a mocking library developed in Erlang. The following is a gist of an example of mocking api calls in Elixir:&lt;/p&gt;
&lt;p&gt;
&lt;script src="https://gist.github.com/cheeyeo/df0c505a135ff3cba328.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/p&gt;
&lt;p&gt;The module under test makes an API call to the Github api to fetch the latest issues for a given project.&lt;/p&gt;
&lt;p&gt;After adding meck as a dependency, I import it into the test using import :meck.&lt;/p&gt;
&lt;p&gt;In the setup block, I created a new mock object using&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:meck.new(Issues.GithubIssues)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The on_exit call unloads :meck and restores the module its original functionality.&lt;/p&gt;
&lt;p&gt;Within the test block, I stubbed out the actual method call using&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:meck.expect(Issues.GithubIssues, :fetch, fn("elixir-lang", "elixir") -&amp;gt; mock_response end)&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;. Every call to Issues.Github.fetch(&amp;ldquo;elixir-lang&amp;rdquo;,&amp;ldquo;elixir&amp;rdquo;) will return the mock response and will not make the actual api call.&lt;/p&gt;
&lt;p&gt;Like in WebMock, we can force the module to make the actual API call using&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:meck.passthrough(["elixir-lang", "elixir"])&lt;/code&gt;&lt;/pre&gt;</description><link>http://blog.29steps.co.uk/post/105715556278</link><guid>http://blog.29steps.co.uk/post/105715556278</guid><pubDate>Sat, 20 Dec 2014 21:09:00 +0000</pubDate><category>elixir</category><category>testing</category><category>mock</category></item><item><title>Mixpanel JS in an enterprise application - some wee notes</title><description>&lt;p&gt;I currently work in a corporate which is progressive in its thinking on how they would like to monitor user behavior and activity in order to provide the best level of service for their customers. One of the biggest projects I was involved with since inception was the integration of Mixpanel into their main website.&lt;/p&gt;
&lt;p&gt;Mixpanel is an event tracking application which allows you to specify which events you would like to track within an application. This is not the same as google analytics say as mixpanel is more powerful than just page or link tracking although that is also built into the library. For more information please visit the mixpanel website for a better explanation.&lt;/p&gt;
&lt;p&gt;We developed a custom piece of JS which is incorporated across their current suite of websites and applications but we hit a barrier, which is the amount of data that could be stored on a client&amp;rsquo;s browser. A typical browser supports only 4k of cookie data from the same domain. If we have multiple applications with subdomains all running mixpanel, that is when disaster strikes as mixpanel stores user data through its own cookies resulting in an overflow issue.&lt;/p&gt;
&lt;p&gt;To overcome this, I came up with the idea of using &lt;strong&gt;localstorage&lt;/strong&gt; to store larger volumes of user activity which are then retrieved from storage at the point it is about to be sent to mixpanel. &lt;a href="http://www.jstorage.info/" title="JStorage" target="_blank"&gt;JStorage &lt;/a&gt;is an excellent integration choice as it has support all the way to IE 7 and has a simple API for retrieving and setting data. By doing that we managed to eliminate the first issue of storing too much data in the user&amp;rsquo;s browser.&lt;/p&gt;
&lt;p&gt;The second issue was with the way mixpanel stores cookies. If you have multiple applications all running with the same domain even subdomains, mixpanel sets a separate cookie for each. Which means if a user visits your main site &amp;lsquo;mysite.com&amp;rsquo; and another application such as 'myapp.mysite.com&amp;rsquo;, mixpanel sets 2 cookies. Coupled that with storing super properties, it would cause an issue.&lt;/p&gt;
&lt;p&gt;This behaviour can be disabled using the following snippet:&lt;/p&gt;
&lt;p&gt;mixpanel.init(&amp;lt;API KEY&amp;gt;, {cross_subdomain_cookie: false})&lt;/p&gt;
&lt;p&gt;The above would only set a single cookie for each subdomain the user visits on your site.&lt;/p&gt;
&lt;p&gt;I hope to provide more concrete examples of the inner workings of mixpanel and some of the pitfalls to avoid in your own applications. &lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/75622187171</link><guid>http://blog.29steps.co.uk/post/75622187171</guid><pubDate>Tue, 04 Feb 2014 21:57:27 +0000</pubDate><category>mixpanel</category><category>enterprise</category></item><item><title>Mongoid currency price search</title><description>&lt;p&gt;In an ongoing project I am working on, I am using the excellent Money gem with money-rails integration within a Rails 3.2 application and running on top of MongoDB.&lt;/p&gt;
&lt;p&gt;If you are familiar with the gem, it stores the price as a type of Money object within mongodb which means typical full text search with greater than or less than will not as expected.&lt;/p&gt;
&lt;p&gt;In order to do a search on price, you would need to create a Money object within the search criteria as follows (assuming my main model is a Product document):&lt;/p&gt;
&lt;p&gt;Product.where(:price =&amp;gt; Money.new(899,&amp;lsquo;EUR&amp;rsquo;)).first&lt;/p&gt;
&lt;p&gt;The above example looks for a product priced at 8.99 euros.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m still in the process of working out how to search for a given price range using the money-rails gem.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/75620479720</link><guid>http://blog.29steps.co.uk/post/75620479720</guid><pubDate>Tue, 04 Feb 2014 21:40:29 +0000</pubDate><category>rails 3.2 money-rails money gem</category><category>ruby</category></item><item><title>Dynamically output HTML within AngularJS</title><description>&lt;p&gt;I recently started to integrate AngularJS into a Rails application which has an external API to speed up the view rendering process and also as an exercise into using another JS framework apart from Backbone.js&lt;/p&gt;
&lt;p&gt;The AngularJS app essentially renders the json output from the existing API and renders it in the view. The only issue is that some of the JSON string is actually raw HTML. If you render this in the view it gets returned as pure string and not actual HTML. Using either &amp;lsquo;raw&amp;rsquo; or &amp;rsquo;.html_safe&amp;rsquo; will not make any difference as the rendering is with Angularjs framework.&lt;/p&gt;
&lt;p&gt;To be able to output dynamic HTML , we would need to make use of the ngSanitize module by including it within the application. These are the steps I took to get the html output to show: &lt;/p&gt;
&lt;ol&gt;&lt;li&gt;include angular-sanitize within application.js
&lt;pre&gt;&lt;code&gt;
//= require angular
//= require angular-resource
//= require angular-sanitize&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Include ngSanitize into your angular module:
&lt;pre&gt;&lt;code&gt;app = angular.module("MyApp", ["ngResource", "ngSanitize"])&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Within the main template use the &lt;strong&gt;ng-bind-html &lt;/strong&gt;directive within the appropriate html tag to display the content:
&lt;pre&gt;&lt;code&gt;&amp;lt;div ng-bind-html='myhtmlstring'&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;Further information and more examples of this usage can be seen on the angularjs site: &lt;a href="http://docs.angularjs.org/api/ngSanitize" title="AngularJS NGSanitize module" target="_blank"&gt;http://docs.angularjs.org/api/ngSanitize.$sanitize&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/60867715914</link><guid>http://blog.29steps.co.uk/post/60867715914</guid><pubDate>Tue, 10 Sep 2013 21:27:00 +0100</pubDate><category>ruby</category><category>Rails 3.2</category><category>angularjs</category></item><item><title>Rebinding UJS actions in Rails 3.2 application</title><description>&lt;p&gt;In a recent rails 3.2 application I am refactoring, some of the js actions had to be redefined to use the &amp;lsquo;on&amp;rsquo; event rather than 'live&amp;rsquo; as that is deprecated since jquery 1.7.&lt;/p&gt;
&lt;p&gt;By doing so some of the events stopped working immediately. This is due to the fact that the 'on&amp;rsquo; event has to be defined on the document body rather than the individual elements in question.&lt;/p&gt;
&lt;p&gt;The example I have provided is a simple example of liking a blog post. The user would see a 'like&amp;rsquo; link within a blog post and upon clicking on the button it would call a UJS action within the rails application which has a corresponding JS template containing certain actions that must be triggered to update the view. If we change the implementation to define 'on&amp;rsquo; event for the like link element once the view gets updated the event is lost until a page refresh.&lt;/p&gt;
&lt;p&gt;If we define it in the context of the document object it persists and no other changes need to be done to the remaining js or UJS template code.&lt;/p&gt;
&lt;p&gt;For further information on how to rewrite 'live&amp;rsquo; actions to 'on&amp;rsquo; please refer to the 'live&amp;rsquo; documentation on the jquery website:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://api.jquery.com/live/" target="_blank"&gt;http://api.jquery.com/live/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Below is a gist of the code in question mentioned above.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/cheeyeo/6435628" title="Gist example" target="_blank"&gt;https://gist.github.com/cheeyeo/6435628&lt;/a&gt;&lt;/p&gt;
&lt;script src="https://gist.github.com/cheeyeo/6435628.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://blog.29steps.co.uk/post/60261145307</link><guid>http://blog.29steps.co.uk/post/60261145307</guid><pubDate>Wed, 04 Sep 2013 12:20:00 +0100</pubDate><category>Rails 3.2</category><category>jquery ujs</category></item><item><title>Refinery CMS is_match() nil after asset compression using closure compiler</title><description>&lt;p&gt;In a recent project using RefineryCMS the page speed analytics results keep indicating that the main application.js after compression is still showing trailing whitespaces and hence triggering &amp;lsquo;js file requires compression&amp;rsquo; warnings when tested within google page speed&lt;/p&gt;
&lt;p&gt;In an attempt to fix this I switched over to using the closure compiler during assets compilation. However after deploy the entire compiled javascript for refinery failed with the following error inside console:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;is_match() is undefined&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This issue is &lt;a href="https://github.com/refinery/refinerycms/pull/2231" target="_blank"&gt;mentioned here&lt;/a&gt; and has been fixed on the main refinerycms master branch on github.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/54208461900</link><guid>http://blog.29steps.co.uk/post/54208461900</guid><pubDate>Sat, 29 Jun 2013 22:51:33 +0100</pubDate><category>ruby</category><category>Rails 3.2</category><category>refinerycms</category></item><item><title>Heroku + Assets + Dragnfly + Optimization + CDN</title><description>&lt;p&gt;In a recent client project, in order to speed up the loading of assets and to improve the overall page speed score, I decided to store the assets outwith of the app and to be able to use the dynamic asset hosts functionality within rails.&lt;/p&gt;
&lt;p&gt;This works really well out of the box apart from one caveat: the app uses Dragonfly to serve dynamic images which gets resized based on certain conditions.&lt;/p&gt;
&lt;p&gt;I originally used asset_sync to store the precompiled assets into Amazon S3 but of course this fails miserably as S3 cannot find images with urls beginning with &amp;rsquo;/system/&amp;rsquo; etc as that is supposed to be handled by the Dragonfly engine whereas asset_sync is looking for a folder or directory path inside S3 &lt;span&gt;!! &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Add to that the complexity of adding in a cloudfront CDN&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The solution I came up in the end was not to use asset_sync but to precompile all the assets before deployment. Then I added a CNAME entry such as &amp;lsquo;assets.mysite.com&amp;rsquo; to point to the actual domain 'mysite.com&amp;rsquo; This is what you would do anyway if you are using asset hosts. Make sure you wait and test the CNAME to make sure it points to the domain 'mysite.com&amp;rsquo; before proceeding further.&lt;/p&gt;
&lt;p&gt;Then within the CDN, set up an origin for 'assets.mysite.com&amp;rsquo; and wait for it to finish setup and turn green. if you start testing before it turns green you will get some weird 503 unavailable errors or your assets will 404 with 'Image returned with type of text/html&amp;rsquo; etc&lt;/p&gt;
&lt;p&gt;Within the config/production.rb add the following line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;config.action_controller.asset_host = "//test.cloudfront.net"&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will make sure that all the assets requests pass through to the CDN rather than the app itself. It also solves the problem of using a dynamic image engine such as Dragonfly while keeping your compiled assets intact  on heroku.&lt;/p&gt;
&lt;p&gt;Another issue to note is that on Heroku cedar stack there is no reverse proxy cache which means your html will not be minified. The following links from heroku mentioned this: &lt;a href="https://devcenter.heroku.com/changelog-items/201" target="_blank"&gt;Link 1&lt;/a&gt; and &lt;a href="https://devcenter.heroku.com/articles/cedar" target="_blank"&gt;Link 2&lt;/a&gt;. This can be fixed by using the &lt;strong&gt;heroku defalter&lt;/strong&gt;&lt;span&gt; gem which will automatically gzip both images and html responses.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In initial tests, the page speed for various pages drop from an intial 4-5ms to under 1ms when the CDN has cached all the assets properly.&lt;/p&gt;
&lt;p&gt;If you still wish to use asset_sync to serve assets from S3 with Dragonfly, there are two possible options:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;
&lt;p&gt;1. Generate a static image for each version required e.g. thumbnail version; actual version&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2. Specify the host within the dragonfly initializer. In my case the dragonfly is within a gem which preloads it so i did not even attempt to spend hours overwriting the initializer.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.29steps.co.uk/post/54207967944</link><guid>http://blog.29steps.co.uk/post/54207967944</guid><pubDate>Sat, 29 Jun 2013 22:43:00 +0100</pubDate><category>ruby</category><category>Rails 3.2</category><category>cdn</category><category>asset pipeline</category></item><item><title>Rails 3 convert superclass to subclass</title><description>&lt;p&gt;In a recent rails 3.0 project I was working on I had an interesting dilemma. I have two models, User and Member. Member is a subclass of User.&lt;/p&gt;
&lt;p&gt;Now when a user logs into the system the system checks what roles and permissions each user has and then redirects them accordingly. e.g. if the user record has a role of &amp;lsquo;Member&amp;rsquo; then we redirect them to the member section.&lt;/p&gt;
&lt;p&gt;Now since Member is a subclass of User, we are using STI ( Single table inheritance ) within rails whereby all the member attributes are stored as columns within the single user table. Member has an additional method called active? which determines if the membership level is active or not. However, in the logic which checks where to redirect signins because only User objects are returned, each call to active? is made on the superclass of User and not Member. To fix this I could redefine active? within the User model but it means duplication of the active? method inside Members class.&lt;/p&gt;
&lt;p&gt;Another alternative would be to convert the User model into a Member object. ActiveRecord instances have a method called &lt;strong&gt;becomes(klass) &lt;/strong&gt;which takes the name of the class to convert to. The definition of becomes from the API docs as follows:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span&gt;Returns an instance of the specified &lt;/span&gt;&lt;code&gt;klass&lt;/code&gt;&lt;span&gt; with the attributes of the current record. This is mostly useful in relation to single-table inheritance structures where you want a subclass to appear as the superclass.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Full link of the api can be found here: &lt;a href="http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-becomes" title="Rails api" target="_blank"&gt;http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-becomes&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now we are going the other way round from superclass to subclass which is unorthodox but works in my case here. An example of what I ended up with:&lt;/p&gt;
&lt;script src="http://www.snipplets.co.uk/snipplets/76.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://blog.29steps.co.uk/post/45831038315</link><guid>http://blog.29steps.co.uk/post/45831038315</guid><pubDate>Wed, 20 Mar 2013 12:24:00 +0000</pubDate><category>Rails 3</category><category>STI</category></item><item><title>Example of refinerycms nested model links with image dialog</title><description>&lt;img src="http://68.media.tumblr.com/fd40eed2cffa390accc3ed28d0ad9579/tumblr_mjx1jrDP831rxv2kio1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/092dbd99fcf3487ee8bf498e386447cd/tumblr_mjx1jrDP831rxv2kio2_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;p&gt;Example of refinerycms nested model links with image dialog&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/45761250209</link><guid>http://blog.29steps.co.uk/post/45761250209</guid><pubDate>Tue, 19 Mar 2013 16:23:51 +0000</pubDate><category>refinerycms rails3 ruby image dialog</category></item><item><title>Nested model partials in Refinery CMS</title><description>&lt;p&gt;In a recent refinerycms project I noticed a strange bug / error after upgrading the system to one of rails&amp;rsquo;s security patches.&lt;/p&gt;
&lt;p&gt;Within a custom engine model, there is a nested form which uses the cocoon gem to show and remove itself. Within the nested form itself, is a link to call the js image picker within refinerycms to select an image for upload. Problem is this: because the nested field is dynamic which means that the image selector link is not generated until the &amp;lsquo;Add This&amp;rsquo; link is clicked and the nested form is on the screen, the image selector link does not get instantiated within a new nested model form.&lt;/p&gt;
&lt;p&gt;This can be seen with this piece of js code from &lt;strong&gt;refinerycms-core ver 1.0.11&lt;/strong&gt;, in &lt;strong&gt;public/javascripts/refinery/admin.js&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
  $(document).ready(function(){
    // other initialization code&lt;br/&gt;    init_modal_dialogs();
  })
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;init_modal_dialogs()&lt;/strong&gt; is a function which opens up a modal window in an iframe for selecting images or attachments. Since my dialog selectors are not going to be present until the nested fields are added, I bind the click event to the live action once the link is clicked. e.g.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
  $('a.add_nested_image_link').live('click', function(e)){
     init_modal_dialogs()
   })
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;This fixes the dialog open and also shows the currently selected image within the nested form.&lt;/p&gt;
&lt;p&gt;To remove the image or to replace it is a bit tricky.&lt;/p&gt;
&lt;p&gt;Refinerycms by default uses a class of &amp;rsquo;.remove_picked_image&amp;rsquo; to define the remove image link within the dialog. Here we have another problem. Since the dialog is not created until the nested model forms are added, we need to bind the 'remove_picked_image&amp;rsquo; links to the live event too else it won&amp;rsquo;t work:&lt;/p&gt;
&lt;script src="http://www.snipplets.co.uk/snipplets/74.js" type="text/javascript"&gt;&lt;/script&gt;&lt;script src="http://www.snipplets.co.uk/snipplets/75.js" type="text/javascript"&gt;&lt;/script&gt;&lt;p&gt;Please note that the above only works if you are using a nested model form within your own engine in refinerycms with the cocoon gem.&lt;/p&gt;
&lt;p&gt;Some screenshots are attached in the post preceding this.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/45759830353</link><guid>http://blog.29steps.co.uk/post/45759830353</guid><pubDate>Tue, 19 Mar 2013 15:56:00 +0000</pubDate><category>Rails 3</category><category>refinerycms</category><category>nested model form</category><category>image picker</category></item><item><title>Money gem + Mongoid</title><description>&lt;p&gt;I have just switched over to using the &lt;strong&gt;money and money-rails gems&lt;/strong&gt; in a recent rails 3.2 app recently &lt;span&gt;after having issues with the formatting and storing of currency values in a Mongoid db. Plus, the money-rails gems comes with some nifty view helpers to transform the values into suitable representations on the front end.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Below are some notes to remind myself how I managed to do this within a Rails 3.2 appli&lt;span&gt;&amp;lt;codebe foRedefine the field within the mongoid document to be of type Money. e.g. Assuming we have a Product document with a field of price, we can define it as follows:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;
&lt;pre&gt;&lt;strong&gt;nufield :price, type: Money&lt;/strong&gt;&lt;/pre&gt;
&lt;p&gt;Once defined the currency values will be stored as a hash in the document with the following structure:&lt;/p&gt;
&lt;pre&gt;&lt;strong&gt;price: {"cents" =&amp;gt; "100", "currency_iso" =&amp;gt; "GBP"}&lt;/strong&gt;&lt;span&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The price value is converted into cents automatically by the gem e.g. 1 USD gets converted into 100 cents. The currency_iso sets the country code of the currency according to the iso 4217 standard which maps the country to a specific currency code.&lt;/p&gt;
&lt;p&gt;The price value is converted into cents automatically by the gem e.g. 1 USD gets converted into 100 cents. This is important to remember else you will end up with strange values.&lt;/p&gt;
&lt;p&gt;Since I will be accessing this value quite frequently i also added an index for it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the money-rails gem to help format the currency values inside views. The gem contains useful helper methods such as &lt;strong&gt;humanized_money_with_symbol&lt;/strong&gt; and &lt;strong&gt;humanized_money&lt;/strong&gt; to convert the currency value into a useful string representation for display.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To help validate against the price value since it is set in a form, I still need to add some validations to make sure that the price value is present and valid.&lt;/p&gt;
&lt;pre&gt;validates :price, :numericality =&amp;gt; {greater_than_or_equal_to: 1.0}, :presence =&amp;gt; true&lt;/pre&gt;
&lt;p&gt;Money gem provides a numerical validator to catch non-integer values such as strings and this can be found inside the money-rails gem lib folder &lt;strong&gt;&amp;lsquo;lib/money-rails/active_model/validator.rb&amp;rsquo;&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Passing in a string value to a money object field through a form does not save it properly for the simple reason that the field is no longer of type string or decimal but of object Money hence any value will need to be converted first before it can be saved.&lt;/p&gt;
&lt;p&gt;To cate for this I created a before_save callback which formats the form value into a money object before saving it:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;before_save :format_price&lt;br/&gt;&lt;br/&gt;def format_price&lt;br/&gt;  self.price = Money.new((BigDecimal.new(self.price.to_s).round(2) * 100).to_i, 'GBP')&lt;br/&gt;end&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The price value needs to be converted into its cents equivalent and its currency code set in the callback.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To test that the attribute returns a Money object on successful save I have the following structure inside my rspec2 model specs:&lt;/p&gt;
&lt;script src="http://www.snipplets.co.uk/snipplets/73.js" type="text/javascript"&gt;&lt;/script&gt;&lt;p&gt;Note that within the tests, the numeric validator within money-rails is testing for the presence of strings and malformed decimal places while the other validations are added by myself.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;I hope the above helps someone to get to grips with using Money and money-rails gems in their own projects. Please comment on better ways of doing the above if you have come across similar setup in your own projects.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/45758087071</link><guid>http://blog.29steps.co.uk/post/45758087071</guid><pubDate>Tue, 19 Mar 2013 15:19:50 +0000</pubDate><category>rails</category><category>Rails 3.2</category><category>MongoDB</category><category>money money-rails</category></item><item><title>likeafieldmouse:

Sayaka Ganz - Emergence (2011) - Discarded...</title><description>&lt;img src="http://68.media.tumblr.com/25c58aead0cdf9444bfbfdcc72d96cc6/tumblr_mjqgei9i8m1qe31lco2_r1_500.png"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/47dad0ac0867fdfabf016b826b0ce30a/tumblr_mjqgei9i8m1qe31lco1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/325ff52aca84a5d74eeb09e86ed43b07/tumblr_mjqgei9i8m1qe31lco3_500.png"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/5fa2546ba475b276cb9c0f907681e7af/tumblr_mjqgei9i8m1qe31lco5_r1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/beb450b5adcea5f341f7206db0fcf3dd/tumblr_mjqgei9i8m1qe31lco4_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;p&gt;&lt;a class="tumblr_blog" href="http://likeafieldmouse.com/post/45469039761/sayaka-ganz-emergence-2011-discarded-plastic" target="_blank"&gt;likeafieldmouse&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://www.sayakaganz.com/" target="_blank"&gt;Sayaka Ganz&lt;/a&gt; - &lt;em&gt;Emergence&lt;/em&gt; (2011) - Discarded plastic&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://blog.29steps.co.uk/post/45753216645</link><guid>http://blog.29steps.co.uk/post/45753216645</guid><pubDate>Tue, 19 Mar 2013 13:24:07 +0000</pubDate></item><item><title>"I’m not gonna sit around and waste my precious divine energy trying to explain and be ashamed of..."</title><description>“I’m not gonna sit around and waste my precious divine energy trying to explain and be ashamed of things you think are wrong with me.”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;Esperanza Spalding (via &lt;a class="tumblr_blog" href="http://likeafieldmouse.com/" target="_blank"&gt;likeafieldmouse&lt;/a&gt;)&lt;/em&gt;</description><link>http://blog.29steps.co.uk/post/45753206127</link><guid>http://blog.29steps.co.uk/post/45753206127</guid><pubDate>Tue, 19 Mar 2013 13:23:50 +0000</pubDate></item><item><title>likeafieldmouse:

Lynda Benglis
</title><description>&lt;img src="http://68.media.tumblr.com/8d362967e786c4c3942ab177a1015b17/tumblr_mjuu9mLkhj1qe31lco1_r1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/dacfa4de69bc9b1f2708776b116d6272/tumblr_mjuu9mLkhj1qe31lco3_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/6b61b3d8bf9290af3eeb5909ad337922/tumblr_mjuu9mLkhj1qe31lco4_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/c11f1fc57728ec993bd1547025000600/tumblr_mjuu9mLkhj1qe31lco5_r1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/aa009c92737b5ee1000bf422088b2c5f/tumblr_mjuu9mLkhj1qe31lco2_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;p&gt;&lt;a class="tumblr_blog" href="http://likeafieldmouse.com/post/45675776108/lynda-benglis" target="_blank"&gt;likeafieldmouse&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://candypingpong.wordpress.com/2011/12/13/the-art-of-lynda-benglis/" target="_blank"&gt;Lynda Benglis&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://blog.29steps.co.uk/post/45752999862</link><guid>http://blog.29steps.co.uk/post/45752999862</guid><pubDate>Tue, 19 Mar 2013 13:18:11 +0000</pubDate></item><item><title>robotcosmonaut:

宇宙怪獣ガメラ
via gurafiku


Back to the eighties...</title><description>&lt;img src="http://68.media.tumblr.com/tumblr_le9qopJDqG1qaz1ado1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a class="tumblr_blog" href="http://robotcosmonaut.tumblr.com/post/45681582177/via-gurafiku" target="_blank"&gt;robotcosmonaut&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://www.imdb.com/title/tt0081675/" target="_blank"&gt;&lt;span class="st"&gt;宇宙怪獣ガメラ&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="st"&gt;via &lt;/span&gt;&lt;a class="tumblr_blog" href="http://gurafiku.tumblr.com/post/2545479548/japanese-movie-poster-super-monster-gamera-1980" target="_blank"&gt;gurafiku&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Back to the eighties again&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/45752972180</link><guid>http://blog.29steps.co.uk/post/45752972180</guid><pubDate>Tue, 19 Mar 2013 13:17:27 +0000</pubDate></item><item><title>Just completed phase 1 of safagrow.com to make it mobile...</title><description>&lt;img src="http://68.media.tumblr.com/6e2a32ed7442b6ec9974aaa3f435f747/tumblr_mjkdt7EfMR1rxv2kio1_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/1c2d6452d9de5977c919bd58cbd2b546/tumblr_mjkdt7EfMR1rxv2kio2_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;img src="http://68.media.tumblr.com/2bdfb87effc5e20971d2400485864220/tumblr_mjkdt7EfMR1rxv2kio3_500.jpg"/&gt;&lt;br/&gt; &lt;br/&gt;&lt;p&gt;Just completed phase 1 of safagrow.com to make it mobile friendly or responsive. The home and blog sections are working and am working on the other sections of the site. Done using Zurb Foundation. Check it out on your mobile. &lt;a href="http://safagrow.com" target="_blank"&gt;safagrow.com&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/45209155684</link><guid>http://blog.29steps.co.uk/post/45209155684</guid><pubDate>Tue, 12 Mar 2013 20:19:55 +0000</pubDate><category>responsive design</category><category>mobile</category></item><item><title>Photo</title><description>&lt;img src="http://68.media.tumblr.com/aa7c5feb03f6b9b2914ca479d1ba963a/tumblr_mjb8q3QO751rxv2kio1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;</description><link>http://blog.29steps.co.uk/post/44808253376</link><guid>http://blog.29steps.co.uk/post/44808253376</guid><pubDate>Thu, 07 Mar 2013 21:51:39 +0000</pubDate></item><item><title>More on SSL - some notes Feb 2013</title><description>&lt;p&gt;My previous post was platform specific and mentions some of the problems I encountered while using the Heroku PAAS using SSL. I aim to be more generic if possible and point out some of the pitfalls I made and to avoid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Applying for your first SSL certificate&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Depending on which hosting provider you use, some providers can apply for a SSL certificate on your behalf while some require you to do the manual work.&lt;/p&gt;
&lt;p&gt;If you are using dedicated hosting such as Parallels with a plesk panel, they provide the private key and CSR request when you click on &lt;strong&gt;&amp;lsquo;Add SSL Certificate&amp;rsquo;&lt;/strong&gt; when you go to the specific domain.&lt;strong&gt; PLEASE USE THESE KEYS TO APPLY FOR YOUR CERTIFICATE. &lt;/strong&gt;I ignored it and had 'hours of turmoil&amp;rsquo; trying to work out what the incompatibilities issues are! Some images are included below for reference.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://68.media.tumblr.com/0950e1dcf6a2da36591738a7f207af64/tumblr_inline_miop4xVwNN1qz4rgp.jpg"/&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="http://68.media.tumblr.com/4b8087d43f68b1b40c6ffa153f983170/tumblr_inline_miop5dt5ko1qz4rgp.jpg"/&gt;&lt;/p&gt;
&lt;p&gt;If you are using your own self generated key and CSR, it is also important to note that some &lt;strong&gt;CAs&lt;/strong&gt; require your CSR to be formatted in a certain way. For example, on RapidSSL, they require you &lt;strong&gt;NOT TO&lt;/strong&gt; add &lt;strong&gt;'email&amp;rsquo;, 'password&amp;rsquo; and 'optional business&amp;rsquo;&lt;/strong&gt; within your CSR request. Other CAs will have similar requirements so make sure you read the DOCS before going any further.&lt;/p&gt;
&lt;p&gt;Some CAs also require an additional level of confirmation before proceeding such as domain verification. This would normally involve sending the ssl email request to a special email address that begins with 'admin@mysite.com&amp;rsquo; or 'administrator@mysite.com&amp;rsquo;. Again make sure these email accounts exist before applying for the SSL certificate.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/43815594214</link><guid>http://blog.29steps.co.uk/post/43815594214</guid><pubDate>Sat, 23 Feb 2013 17:43:02 +0000</pubDate><category>ssl</category><category>security</category></item><item><title>Heroku SSL Endpoint + Rails 3.2</title><description>&lt;p&gt;I had the opportunity to deploy and use SSL on heroku and it has been a while since I had to do this. Heroku&amp;rsquo;s SSL has now been moved to a dedicated endpoint which means all https traffic to your heroku app will be re-routed from the endpoint to &amp;lt;yourapp.herokuapp.com&amp;gt;&lt;/p&gt;
&lt;p&gt;After setting up and deploying the SSL certificates to heroku successfully, I realised i had to set a DNS CNAME entry for the SSL endpoint.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This raises an interesting problem: the Heroku application I am working on already has a CNAME record pointing to the heroku domain. If you change the CNAME setting to just the SSL endpoint then the entire app cannot be found.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;The way I found to resolve this is as follows:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Within your DNS panel set an ALIAS to &amp;lt;yourapp.herokuapp.com&amp;gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Change the CNAME entries for &amp;lt;yourapp.herokuapp.com&amp;gt; to point to the ssl endpoint e.g. &amp;lt;ssl.herokuapp.com&amp;gt;. This can be found using the command &lt;strong&gt;heroku certs from the application directory&lt;/strong&gt;. If you have setup the certificates properly this will show you a table with the matching ssl endpoint and your app url.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Within your app make sure that config.force_ssl = true if you are using SSL for the entire app or create your own custom ssl filters inside application_controller.rb or otherwise.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;&lt;span&gt;If it all goes well you should see your site with a lock icon and your certificate details should be shown:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt="image" src="http://68.media.tumblr.com/23def0cbc1cfa740487491e5258207fc/tumblr_inline_mionu6HURC1qz4rgp.jpg"/&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;I bought the SSL certificate from Rapid SSL and it was processed within minutes and another half an hour to figure out how to setup and to implement SSL. There are some pitfalls to avoid when registering your SSL certificate for the first time and this will be highlighted in the next article from this.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I used to think that SSL is an &amp;lsquo;addon&amp;rsquo; and only required if you are doing ecommerce or storing some form of personal information. With the levels and frequency of hacking attempts made I think the initial investment is worthwhile for peace of mind for your data security and integrity. Even though SSL does not prevent or stop any hacking or hijacking attempts at your app or site at least it is a level of defense or barrier between you and the dangers out there rather than having none at all.&lt;/p&gt;
&lt;p&gt;For a more detailed discussion or article on why SSL is important check out this article on html5rocks:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.html5rocks.com/en/tutorials/security/transport-layer-security/" target="_blank"&gt;http://www.html5rocks.com/en/tutorials/security/transport-layer-security/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below are links for setting up SSL on heroku:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/ssl-endpoint" target="_blank"&gt;https://devcenter.heroku.com/articles/ssl-endpoint&lt;span&gt; &lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/ssl-certificate" target="_blank"&gt;&lt;span&gt;&lt;a href="https://devcenter.heroku.com/articles/ssl-certificate" target="_blank"&gt;https://devcenter.heroku.com/articles/ssl-certificate&lt;/a&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devcenter.heroku.com/articles/ssl#customdomain-ssl" target="_blank"&gt;https://devcenter.heroku.com/articles/ssl#customdomain-ssl&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please pay attention to 'Preparing your SSL certificate&amp;rsquo; section as it requires merging your CA (Certificate Authority) intermediate cert with your issued certificate.&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/43813723472</link><guid>http://blog.29steps.co.uk/post/43813723472</guid><pubDate>Sat, 23 Feb 2013 17:17:00 +0000</pubDate><category>rails 3.2</category><category>heroku ssl</category></item><item><title>Postgresql Shared Memory error</title><description>&lt;p&gt;Ran into this interesting issue this morning while playing around with Rails 4.0. Normally postgresql would just run after running pg_ctl but this time it did not appear inside the process list. Upon checking the log file this is the error that was shown:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;FATAL:  could not create shared memory segment: Cannot allocate memory&lt;/p&gt;
&lt;p&gt;DETAIL:  Failed system call was shmget(key=5432001, size=3809280, 03600).&lt;/p&gt;
&lt;p&gt;HINT:  This error usually means that PostgreSQL&amp;rsquo;s request for a shared memory segment exceeded available memory or swap space, or exceeded your kernel&amp;rsquo;s SHMALL parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMALL.  To reduce the request size (currently 3809280 bytes), reduce PostgreSQL&amp;rsquo;s shared memory usage, perhaps by reducing shared_buffers or max_connections.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;What this means is that there is insufficient shared memory to start the postgresql process. in my case it was caused by running virtualbox in the background.&lt;/p&gt;
&lt;p&gt;What I did to solve the above was this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;sudo sysctl -w kern.sysv.shmall=65536&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The command increases the shared memory usage system wide and postgresql was able to run again. To make this appear after reboot you also need to do add this to /etc/sysctl.conf:&lt;/p&gt;
&lt;blockquote&gt;kern.sysv.shmall=65536&lt;/blockquote&gt;
&lt;p&gt;Works for me on OS X Lion&lt;/p&gt;</description><link>http://blog.29steps.co.uk/post/40011160744</link><guid>http://blog.29steps.co.uk/post/40011160744</guid><pubDate>Tue, 08 Jan 2013 13:51:53 +0000</pubDate><category>postgresql</category><category>rails 4.0</category></item></channel></rss>
