<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>myGrid developer blog</title>
	<atom:link href="http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=34" rel="self" type="application/rss+xml" />
	<link>http://dev.mygrid.org.uk/blog</link>
	<description>The developers of myGrid tell of their quest of the code</description>
	<lastBuildDate>Fri, 17 May 2013 08:52:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.1</generator>
		<item>
		<title>Ember JS: Server side</title>
		<link>http://dev.mygrid.org.uk/blog/?p=121</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=121#comments</comments>
		<pubDate>Thu, 16 May 2013 15:44:15 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[ember-data]]></category>
		<category><![CDATA[emberjs]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://dev.mygrid.org.uk/blog/?p=121</guid>
		<description><![CDATA[Creating the rails app In the Ember JS MVC tutorials we created a purely browser based application with no persistence between sessions and hard coded fixtures for data. In this article we will create a server side app to handle &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=121">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Creating the rails app</h2>
<p>In the Ember JS MVC tutorials we created a purely browser based application with no persistence between sessions and hard coded fixtures for data. In this article we will create a server side app to handle data persistence, we will also use it to serve our Ember application. We will use Ruby on Rails. The code is available <a title="Basic rails and ember  application code" href="https://github.com/ianwdunlop/ember-js-rails-blog/archive/v1.1.zip">here</a> in zip form or if you want to fork etc on github try <a title="Basic ember rails app repository" href="https://github.com/ianwdunlop/ember-js-rails-blog">here</a>. Start by creating a new rails application</p>
<blockquote>
<pre>rails new blog</pre>
</blockquote>
<p>Wait for the app to be created, go in to the blog directory and remove <code>public/index.html</code>. You can use ember-rails to create the ember client side skeleton code but we will do it by hand using the classes and templates we created during the <a title="Ember JS MVC tutorial part 1" href="http://dev.mygrid.org.uk/blog/?p=46">MVC tutorials</a>. I find it is helps you to understand how the application works if you use as little auto-generated code as possible. However, we will use some rails scaffold to get us started.</p>
<blockquote>
<pre>rails generate scaffold Post title:string content:text
rails generate scaffold Comment text:string post_id:integer</pre>
</blockquote>
<p>This creates the controllers, views, model, helper, db migrations etc. Then we can create the database.</p>
<blockquote>
<pre>rake db:migrate
rake db:create</pre>
</blockquote>
<p>As we defined in the MVC tutorial a Post can have many Comments so add the relationships to the rails models, in blog/app/models.</p>
<blockquote>
<pre>add belongs_to :post to comment model
add has_many :comments to post model</pre>
</blockquote>
<p>In routes we have resource for posts and comments, add a root</p>
<blockquote>
<pre>root :to =&gt; 'welcome#index'</pre>
</blockquote>
<p>We therefore need something for this route to render. Create a <code>welcome_controller.rb</code> in <code>app/controllers</code> with an <code>index</code> method and a index view for it in <code>app/views/welcome/index.html.erb</code>. The view will be empty, it is just a placeholder for our rails app to boot the root ie /. Ember will be doing all the rendering.</p>
<blockquote>
<pre>class WelcomeController &lt; ApplicationController
  # GET / 
  def index 
    respond_to do |format| 
      format.html # index.html.erb 
    end 
  end 
end</pre>
</blockquote>
<h2>Add the Ember application</h2>
<p>Just like in a rails app we can make our ember application easier to manage by creating an ember app structure in <code>app/assets/javascripts</code>. ember-rails would do this for you.</p>
<blockquote>
<pre>/controllers 
/templates 
/models 
/views 
/helpers</pre>
</blockquote>
<p>Using the code from <code>app.js</code> and <code>index.html</code> from part 3 of the tutorial create the following files</p>
<p><code>controllers/commentsNewController.js</code></p>
<blockquote>
<pre>App.CommentsNewController=Ember.ObjectController.extend({
  needs: 'post',
  text: null,
  save: function() {
    var post = this.get('controllers.post.content');
    App.Comment.createRecord({ post: post, text: this.get('text') }); 
    this.get('target').transitionTo('post.index');
   }
});</pre>
</blockquote>
<p><code>models/post.js</code></p>
<blockquote>
<pre>App.Post=DS.Model.extend({
  comments: DS.hasMany('App.Comment'),
  title: DS.attr('string')
});</pre>
</blockquote>
<p><code>models/comment.js</code></p>
<blockquote>
<pre>App.Comment = DS.Model.extend({
  post: DS.belongsTo('App.Post'),
  text: DS.attr('string')
});</pre>
</blockquote>
<p>The templates directory structure mimics the <code>data-template-name</code> from <code>index.html</code></p>
<blockquote>
<pre>/templates
/templates/comments
/templates/comments/new.hbs
/templates/post
/templates/post/comment.hbs
/templates/post/index.hbs
/templates/application.hbs
/templates/comments.hbs
/templates/index.hbs
/templates/post.hbs
/templates/posts.hbs</pre>
</blockquote>
<p>Copy the contents of the script tags in <code>index.html</code> from <a title="Ember JS MVC tutorial part 3" href="http://dev.mygrid.org.uk/blog/?p=97">part 3 of the MVC</a> tutorial to the appropriate template, you do not need the enclosing script tag itself. We also need to add a <code>router.js</code> to the <code>app/assets/javascript</code> directory, use the code from <code>app.js</code> we created in <a title="Ember JS MVC tutorial part 3" href="http://dev.mygrid.org.uk/blog/?p=97">part 3</a>.</p>
<blockquote>
<pre>App.Router.map(function() {
  this.resource('posts');
  this.resource('post', { path: '/posts/:post_id' }, function() {
    this.resource('comments', function() {
      this.route('new');
    });
  this.route('comment', { path: 'comments/:comment_id'});
  });
});

App.PostsRoute=Ember.Route.extend({
  model: function(){
    return App.Post.find();
  }
});

App.PostIndexRoute=Ember.Route.extend({
  model: function(params) {
    return this.modelFor('post');
  }
});

App.CommentsNewRoute=Ember.Route.extend({
  setupController: function(controller, model) {
    controller.set('text', null);
  }
});</pre>
</blockquote>
<p>Our <code>store.js</code> no longer uses the fixture adapter but uses the rest adapter. Add <code>store.js</code> to <code>app/assets/javascripts</code> and put the following code in it.</p>
<blockquote>
<pre>App.Store = DS.Store.extend({
  revision: 12,
  adapter: DS.RESTAdapter.create({
    bulkCommit: false
  })
});</pre>
</blockquote>
<h2>Serve the javascript from rails</h2>
<p>It is advisable to use the latest stable version of ember and ember-data. Download ember-latest.js &amp; ember-data-latest.js from <a title="latest ember and ember-data builds" href="http://builds.emberjs.com/">http://builds.emberjs.com/</a> and put in vendor/assets/javascripts Add the <a title="Handlebar assets gem " href="http://rubygems.org/gems/handlebars_assets">handlebars_assets</a> gem to the Gemfile so that we load <code>handlebars.js</code> and get the assets pipeline to compile our handlebars templates. You may have noticed that we append .hbs to them since this is what the gem looks for rather than .handlebars. We also need to load our ember application javascript files, create a <code>blog.js</code> file</p>
<blockquote>
<pre>//= require ./store
//= require_tree ./models
//= require_tree ./controllers
//= require_tree ./views
//= require_tree ./helpers
//= require_tree ./templates
//= require ./router
//= require_self</pre>
</blockquote>
<p>Then add <code>blog</code>, <code>handlebars</code>, <code>ember</code> and <code>ember-data</code> to <code>application.js</code>. Also create our ember app instance inside there.</p>
<blockquote>
<pre>//= require jquery
//= require jquery_ujs
//= require handlebars
//= require ember-latest
//= require ember-data-latest
//= require_self
//= require blog

window.App = Ember.Application.create({
  LOG_TRANSITIONS: true
});</pre>
</blockquote>
<p>Start a rails server with <code>rails s</code> and go to <code>localhost:3000</code> in a browser. You should see the Blog index page with a link to &#8216;Posts&#8217;. Open up the debugger to look at the network traffic. Click on the Posts link and you will see a request to <code>localhost:3000/posts</code>. The response is empty but the application transitions to posts.</p>
<h2>Add some data and respond with JSON</h2>
<p>We will now add some data for the server to send to the browser. Add some db seeds to <code>db/seeds.rb</code></p>
<blockquote>
<pre>post = Post.create( :title =&gt; 'First post', :content =&gt; 'Text for first post' )
Comment.create(:text =&gt; 'Post one comment one', :post_id =&gt; post.id)
Comment.create(:text =&gt; 'Post one comment two', :post_id =&gt; post.id)
post = Post.create( :title =&gt; 'Second post', :content =&gt; 'Text for second post' )
Comment.create(:text =&gt; 'Post two comment one', :post_id =&gt; post.id)
Comment.create(:text =&gt; 'Post two comment two', :post_id =&gt; post.id)
post = Post.create( :title =&gt; 'Third post', :content =&gt; 'Text for third post' )
Comment.create(:text =&gt; 'Post three comment one', :post_id =&gt; post.id)
Comment.create(:text =&gt; 'Post three comment two', :post_id =&gt; post.id)</pre>
</blockquote>
<p>Use <code>rake db:seed</code> to add the posts and comments. We also need to make sure that our rails application serves JSON in the correct format. We need to add the correct JSON serialiser to the post model to include the comments as comment_ids array. Ember needs the JSON response in the format <code>"posts" : [{...},{...}]</code></p>
<blockquote>
<pre>def as_json(options={})
  { :id =&gt; self.id, :title =&gt; self.title, :content =&gt; self.content, :comment_ids =&gt;self.comments.collect{|comment| comment.id} }
end</pre>
</blockquote>
<p>We then need to change the posts controller index method to render json using this method</p>
<blockquote>
<pre>format.json { render :json =&gt; { :posts =&gt; @posts.as_json } }</pre>
</blockquote>
<p>as well as in the show method</p>
<blockquote>
<pre>format.json { render :json =&gt; { :post =&gt; @post.as_json } }</pre>
</blockquote>
<p>We also need to change the JSON response in the comments controller show method to</p>
<blockquote>
<pre>format.json { render :json =&gt; { :comment =&gt; @comment } }</pre>
</blockquote>
<p>so that the json is returned as <code>"comment" : {....}</code></p>
<p>(see <a title="Rails to_json v as_json" href="http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/">http://jonathanjulian.com/2010/04/rails-to_json-or-as_json/</a>)</p>
<p>When fetching the comments ember will request it as <code>/comments?ids[]=1&amp;ids[]=2</code> ie as an array of ids, change the comments_controller index method to handle that</p>
<blockquote>
<pre>if params[:ids]
  @comments = []
  params[:ids].each do |id|
    @comments.push(Comment.find(id))
  end
  else
   @comments = Comment.all
end
respond_to do |format|
  format.html # index.html.erb
  format.json { render :json =&gt; { :comments =&gt; @comments } }
end</pre>
</blockquote>
<h2>Save new comments to the server</h2>
<p>We need to change the <code>CommentsNewController</code> save method so that it sends a POST request to <code>/comments</code> with the new comment in JSON. Change it to:</p>
<blockquote>
<pre>var post = this.get('controllers.post.content');
var comment = App.Comment.createRecord({ post: post, text: this.get('text') });
comment.get("store").commit(); //this is the new bit, after creating a comment we need to commit it
this.get('target').transitionTo('post.index');</pre>
</blockquote>
<p><code>comment.get("store").commit()</code> tells the comment to commit itself.<br />
Go to <code>/posts/1/comments/new</code>, enter a comment and hit save. You will see some network traffic heading to /comments on the server. Refresh /posts/1 and you will see that it has the new comment. You can use the rails console to convince yourself. <code>Comment.all</code> will have the new one at the end. We can use exactly the same principles to create new posts, why not add it to your app?</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=121</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ember JS: MVC in the browser. Part 3 &#8211; Nested Resources</title>
		<link>http://dev.mygrid.org.uk/blog/?p=97</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=97#comments</comments>
		<pubDate>Mon, 13 May 2013 13:32:25 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[emberjs]]></category>
		<category><![CDATA[handlebars]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://dev.mygrid.org.uk/blog/?p=97</guid>
		<description><![CDATA[In part 2 we created templates so that we could view any of our blog posts along with the models and controller actions to support this. We also used ember-data to create a store which uses a FixtureAdapter along with &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=97">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a title="Ember JS Tutorial part 2" href="http://dev.mygrid.org.uk/blog/?p=75">part 2</a> we created templates so that we could view any of our blog posts along with the models and controller actions to support this. We also used ember-data to create a store which uses a FixtureAdapter along with some hardcoded <code>Post</code> fixtures to load our models. A <code>Post</code> with a title is not much use on its own, we also want people to be able to add comments. We will have to extend the post route to add a nested resource. We will also need a new model to represent the nested resource. The code for this part is available <a title="Code for part 3" href="https://github.com/ianwdunlop/ember-js-mvc-blog-tutorial/archive/part3.zip">here</a>. Open app.js in an editor and change the post route to match the following:</p>
<blockquote>
<pre>this.resource('post', { path: '/posts/:post_id' }, function() {
  this.resource('comments');
});</pre>
</blockquote>
<p>This means we will now have a <code>/posts/:post_id/comments</code> route.</p>
<p>Open the index.html page in a browser and examine the routes in the console. Remember our old friend <code>Router.router.recognizer.names</code>? (btw. I noticed in Firefox you may need to use <code>App.Router.router.recognizer.names</code>). You will see that <code>comments</code> route has been added. Lets add a comments model and fixtures. Add the following to app.js</p>
<blockquote>
<pre>App.Comment = DS.Model.extend({
  post: DS.belongsTo('App.Post'),
  text: DS.attr('string')
});</pre>
</blockquote>
<p>and add the following within the <code>App.Post</code> model making sure that you have a comma between any lines</p>
<blockquote>
<pre>comments: DS.hasMany('App.Comment')</pre>
</blockquote>
<p>Each Post can now have many Comment(s). Add some comment fixtures to app.js:</p>
<blockquote>
<pre>App.Comment.FIXTURES = [{id:"1", text: "First Comment"}, {id:"2", text: "Second Comment"}, {id:"3", text: "Third Comment"}, {id:"4", text: "Fourth Comment"}, {id:"5", text: "Fifth Comment"}, {id:"6", text: "Sixth Comment"}, {id:"7", text: "Seventh Comment"}, {id:"8", text: "Eighth Comment"}, {id:"9", text: "Ninth Comment"}];</pre>
</blockquote>
<p>We also need to change the <code>Post</code> fixtures to tell them that they have some comments:</p>
<blockquote>
<pre>App.Post.FIXTURES=[{ id: "1", title: "First Post", comments: [1, 2, 3] }, { id: "2", title: "Second Post", comments: [4, 5, 6] }, { id: "3", title: "Third Post", comments: [7, 8, 9] }];</pre>
</blockquote>
<p>Note that we have added a &#8216;comments&#8217; attribute in each Post fixture with an array of the Comments they have. <code>[1, 2, 3]</code> means that this Post has the Comments with ids 1, 2 &amp; 3. Go to /posts/1/comments/1 to check that they render correctly.</p>
<p>Change the <code>post/index</code> template to the following so that we can see the comments:</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="post/index"&gt;
  {{title}}
  &lt;ul&gt;
    {{#each comment in comments}}
      &lt;li&gt;{{comment.text}}&lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/script&gt;</pre>
</blockquote>
<p>Go to <code>/posts/1</code> and you should see the text for each Comment appearing under the Post title.</p>
<p>We can now add a link to each comment but before this we need to tell the router how to route to them. We want the route to look like <code>/posts/:post_id/comments/:comment_id</code><br />
To achieve this we need to add the following to the posts resource router definition</p>
<blockquote>
<pre>this.route('comment', { path: 'comments/:comment_id'});</pre>
</blockquote>
<p>We will also need a post.comment template in index.html</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="post/comment"&gt;
  {{text}}
&lt;/script&gt;</pre>
</blockquote>
<p>What if we wanted to add a new comment to a post? We will add a <code>posts/:post_id/comments/new</code> route and templates. Change the comments resource under the post resource in the router to</p>
<blockquote>
<pre>this.resource('comments', function() {
  this.route('new');
});</pre>
</blockquote>
<p>Then add a comments outlet template and a &#8216;new&#8217; one</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="comments"&gt;
  {{outlet}}
&lt;/script&gt;

&lt;script type="text/x-handlebars" data-template-name="comments/new"&gt;
  Comments New
&lt;/script&gt;</pre>
<pre></pre>
<p>&nbsp;</p></blockquote>
<p>If you refresh and look at the available routes we now have <code>comments.new</code>. Go to <code>/posts/1</code> and click on the <code>New Comment</code> link and you should see the &#8220;Comments New&#8221; text. Not much use though, we need a text box for the comment and a button to submit. Add the following to the comments/new handlebars template</p>
<blockquote>
<pre>&lt;form {{action save on='submit'}}&gt;
  {{view Ember.TextArea valueBinding="text" placeholder="Enter comment here"}}
  &lt;button type="submit"&gt;Create Comment&lt;/button&gt;
&lt;/form&gt;</pre>
</blockquote>
<p>Here we tell the template that when the forms &#8220;Create Comment&#8221; button is clicked, ie on submit, it should call the &#8220;save&#8221; action in the <code>CommentsNewController</code>. We need to create that controller. In the TextArea we have bound the &#8220;text&#8221; value to the controller. Add the following to app.js</p>
<blockquote>
<pre>App.CommentsNewController=Ember.ObjectController.extend({
  needs: 'post',
  text: null,
  save: function() {
    var post = this.get('controllers.post.content');
    App.Comment.createRecord({ post: post, text: this.get('text') });
    this.get('target').transitionTo('post.index');
  }
});</pre>
</blockquote>
<p>Firstly we tell this controller that it needs to know about the <code>PostController</code> so that it can tell what post the comment is for. We do this through <code>needs: 'post'</code>. The <code>text: null</code> bit is the value we have bound to the <code>TextArea</code> in the template. The save function is what happens when we click the button. Firstly it finds the post through <code>controllers.post.content</code> (facilitated via the &#8216;needs&#8217; syntax), the we create a new <code>Comment</code> with the text value. Finally we transition back to the post. <code>this.get('target')</code> gives us an instance of the router. Try adding a new comment and see what happens. Note that since we are using the <code>FixturesAdapter</code> the ids may look a little bit odd.</p>
<p>One final thing we should do is reset the comments <code>TextArea</code> box in the <code>comments/new</code> template when we transition to the route. If we don&#8217;t then it will contain the last thing we entered in to it. Add this to app.js</p>
<blockquote>
<pre>App.CommentsNewRoute=Ember.Route.extend({
  setupController: function(controller, model) {
    controller.set('text', null);
  }
});</pre>
</blockquote>
<p><code>setupController</code> is a hook that all routes have and allows you to set the model or modify the controller.</p>
<p>To recap, we created a comments nested resource for post and added the route &#8216;new&#8217; to it. We added a <code>Comment</code> model and fixtures and linked them to the <code>Post</code> model via <code>hasMany</code> and <code>belongsTo</code>. We added the comments to the <code>post.index</code> template and added a route with a path for each <code>post.comment</code> so we could link to them. We created the <code>comments.new</code> template with a form that we could submit and the <code>CommentsNewController</code> with a save action to create the new comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=97</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ember JS: MVC in the browser. Part 2 &#8211; Templates</title>
		<link>http://dev.mygrid.org.uk/blog/?p=75</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=75#comments</comments>
		<pubDate>Tue, 07 May 2013 10:22:53 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[emberjs]]></category>
		<category><![CDATA[handlebars]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://dev.mygrid.org.uk/blog/?p=75</guid>
		<description><![CDATA[In part one we added some routes defining our posts resource and for an individual post. We also learned how to inspect our Router object to see what we had defined using App.Router.router.recognizer.names in the web console. Now to create &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=75">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In <a title="Ember JS routing" href="http://dev.mygrid.org.uk/blog/?p=46">part one</a> we added some routes defining our posts resource and for an individual post. We also learned how to inspect our Router object to see what we had defined using <code>App.Router.router.recognizer.names</code> in the web console. Now to create some templates to display when we transition through our routes. Download the code <a title="code for part 2 of the tutorial" href="https://github.com/ianwdunlop/ember-js-mvc-blog-tutorial/archive/part2.zip">here</a>. In part one we defined an application template with a handlebars <code>{{outlet}}</code>. We will add templates to render in this outlet.</p>
<p>Go back to index.html and add the following:</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="index"&gt;
  {{#linkTo 'posts'}}Posts{{/linkTo}}
&lt;/script&gt;

&lt;script type="text/x-handlebars" data-template-name="posts"&gt;
  Posts
&lt;/script&gt;</pre>
</blockquote>
<p>Refresh the page and you should see a link to &#8216;Posts&#8217; under the title, clicking on it will take you to a page with the title and the word &#8216;Posts&#8217;. Looking at the console you can see that we transitioned from index to posts. Both of these templates were rendered in the main application template in the <code>{{outlet}}</code> block. Next we can add a link to individual Posts inside the Posts template and create a template for these individual Posts.</p>
<p>Change the &#8216;posts&#8217; template to the following</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="posts"&gt;
  &lt;ul&gt;
    {{#each model}}
      &lt;li&gt;{{#linkTo post this}}{{title}}{{/linkTo}}&lt;/li&gt;
    {{/each}}
  &lt;/ul&gt;
&lt;/script&gt;</pre>
</blockquote>
<p>However, if you refresh the &#8216;/posts&#8217; page you will no longer see anything. That is because we have no models and we definitely have no data. To remedy this we will add some. We start by creating a store. Go to app.js and add the following</p>
<blockquote>
<pre>App.Store = DS.Store.extend({
  revision: 12,
  adapter: 'DS.FixtureAdapter'
});</pre>
</blockquote>
<p>If you refresh the page you will probably see an error along the lines of &#8216;Undefined variable: DS&#8217;. This is because we need to add the ember-data library. To get it you can either clone the ember-data repository and run <code>rake dist</code> (<a title="Ember Data" href="https://github.com/emberjs/data#getting-ember-data">https://github.com/emberjs/data#getting-ember-data</a>) or download the latest build from <a title="Get latest build of ember data" href="http://builds.emberjs.com">http://builds.emberjs.com</a>). In the future ember-data may be bundled along with ember but until then this is the way to get it.</p>
<p>So, download ember-data, add a <code>&lt;script&gt;</code> tag to index.html to load it, placing it after ember but before app.js, and refresh again. Now, the <code>revision: 12</code> part is to check that it is compatible with the emberjs you are using, if not it will be reported in the console. The adapter part is optional but we are telling it to load data from fixtures that we will specify in javascript. Reload and all should be ok. We will now define a post model and some fixtures. Add the following to app.js</p>
<blockquote>
<pre>App.Post=DS.Model.extend({
  title: DS.attr('string')
});

App.Post.FIXTURES=[{ id: "1", title: "First Post" }, { id: "2", title: "Second Post" }, { id: "3", title: "Third Post" }];</pre>
</blockquote>
<p>Refresh the page and&#8230;..nothing. We have to tell ember what to do when it gets to the posts route. Add the following to app.js, after the main routes definition.</p>
<blockquote>
<pre>App.PostsRoute=Ember.Route.extend({
  model: function(){
    return App.Post.find();
  }
});</pre>
</blockquote>
<p>Here we tell ember that when we transition to &#8216;posts&#8217; we need to find all the Post models that exist, in this case we return all the fixtures we have created. Refresh and all the posts should be shown using the title as a link. If you look at the definition for the posts template we created earlier you can see that we iterate over each of the models that the <code>PostsRoute</code> returns and add a link for each with the title as the text. <code>{{title}}</code> is a handlebars helper which tells it to get the attribute title from the current model in scope. Refresh the page and you should see links to 3 posts, hover over them to see the urls they link to. They should be linking to /posts/1 etc. Click on one of the links and you will see that we transition into post.index but there is nothing shown. Surprise, surprise we need a to define a template. Add the following to index.html after the currently defined templates:</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="post/index"&gt;
  {{title}}
&lt;/script&gt;</pre>
</blockquote>
<p>Refresh the page and you will see this warning in the console:</p>
<p><code>WARNING: the immediate parent route ('a') did not render into the main outlet and the default 'into' option ('p') may not be expected</code></p>
<p>Rember earlier we defined the <code>{{outlet}}</code> in the application template, ember expects every parent template to have an <code>{{outlet}}</code> into which it can render its children. In this case it is saying that it wants to render post.index into post but it can&#8217;t find it. We need to define a post template with the following in index.html</p>
<blockquote>
<pre>&lt;script type="text/x-handlebars" data-template-name="post"&gt;
  Post
  {{outlet}}
&lt;/script&gt;</pre>
</blockquote>
<p>Don&#8217;t forget to add the &#8216;Post&#8217; text in the template, you will see why in a second. Refresh and you will see the &#8216;Post&#8217; text but no title for the post. Well, it turns out there is a &#8216;feature&#8217; (polite term for a bug) which means that in the current version the &#8216;default&#8217; behaviour for a parameterised route does not work out of the box. Ember should know that because we defined the route with /posts/:post_id that it should return the model with id equal to :post_id when we transition to post.index with posts/1 etc but for the moment we have to tell it. We need to define a PostIndexController to get things back on track. Add the following code to app.js so we can see what is happening:</p>
<blockquote>
<pre>App.PostIndexRoute=Ember.Route.extend({
  model: function(params) {
    return App.Post.find(params.post_id);
  }
});</pre>
</blockquote>
<p>Refresh and&#8230;.still nothing. Ok, I knew that was going to happen, unfortunately the bug means that empty params are passed to a nested route. Use your debugger and examine the params object yourself. All is not lost however, change the model hook to</p>
<blockquote>
<pre>model:function(params) {
  return this.modelFor('post');
}</pre>
</blockquote>
<p>Refresh. Yes, you should now see the text &#8216;Post First Post&#8217;. You can remove the unneeded &#8216;Post&#8217; text from the post template and refresh again. Try going to posts/2 and posts/3 to convince yourself that it is all working.</p>
<p>So to recap. We have created an ember application which logs transitions between routes. It has 3 routes: index, posts and post.index. We have 5 templates: the main application one with <code>{{outlet}}</code>. The index template ie &#8216;/&#8217;. The posts template. A post template with an outlet for its nested routes and a post.index template to &#8216;show&#8217; each post. In part 3 we will look at nested routes.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=75</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ember JS: MVC in the browser. Part 1 &#8211; Routing</title>
		<link>http://dev.mygrid.org.uk/blog/?p=46</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=46#comments</comments>
		<pubDate>Wed, 01 May 2013 15:36:08 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[emberjs]]></category>
		<category><![CDATA[handlebars]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://dev.mygrid.org.uk/blog/?p=46</guid>
		<description><![CDATA[Ember JS is a Javascript client side MVC framework featuring all your favourite constructs such as controllers, models, views and routing. Client side means that it all runs inside the browser meaning that rendering times are extremely fast with no &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=46">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ember JS is a Javascript client side MVC framework featuring all your favourite constructs such as controllers, models, views and routing. Client side means that it all runs inside the browser meaning that rendering times are extremely fast with no calls to the server to fetch pages. Ember has an optional restful data model called ember-data which handles the GET/PUT/POST/DELETE lifecycle of your models. Go to <a href="http://emberjs.com">http://emberjs.com</a> and download the starter kit which I used as the skeleton for this application or download the complete code for this part of the tutorial <a title="code for part 1 of the tutorial" href="https://github.com/ianwdunlop/ember-js-mvc-blog-tutorial/archive/part1.zip">here</a>. Have a look at the video tutorial as well, you will no doubt recognise some overlap with these posts. I primarily wrote this to get everything I had learned about ember in one place, I found the emberjs.com tutorials very useful but also unordered and was constantly flicking between various different sites, stack overflow etc. We will be building a simple blog application using a lot of the facts that can be found in the emberjs.com tutorials but with some pointers and helpers along the way. We will look at the ember components needed to handle the model lifecycle and views and later will write server side code to find, create and save the models. You can use any server framework you like but I prefer to use rails however ASP.net or whatever are just as good as long as they can handle REST and JSON. We will also look at using CORS or JSONP to load data directly to the browser.</p>
<p>For me it was easier to think of an ember app in terms of a rails one so where better to start than with the routes. Our simple application will consist of posts which can have many comments. In Rails (3.x) your routes file would consist of a root and some resources corresponding to the models. So lets say you use some scaffolding to get started</p>
<blockquote>
<pre>rails new blog
rails generate scaffold Post name:string title:string content:text</pre>
</blockquote>
<p>This gives us the following in config/routes.rb</p>
<blockquote>
<pre>resources :posts</pre>
</blockquote>
<p>We would also normally add a root after deleting public/index.html</p>
<blockquote>
<pre>root :to =&gt; 'welcome#index'</pre>
</blockquote>
<p><code>rake routes</code> shows:</p>
<blockquote>
<pre>posts GET /posts(.:format) posts#index
POST /posts(.:format) posts#create
new_post GET /posts/new(.:format) posts#new
edit_post GET /posts/:id/edit(.:format) posts#edit
post GET /posts/:id(.:format) posts#show
PUT /posts/:id(.:format) posts#update
DELETE /posts/:id(.:format) posts#destroy
root / welcome#index</pre>
</blockquote>
<p>We want to create a similar route structure in ember.</p>
<p>To begin with we will keep all the html and UI bits in index.html and all the application logic in app.js (look inside the js directory to find it). The ember starter pack has an example index.html, open it in your browser and you will see that it renders a simple page with 3 colours listed. Have a look at it in an editor and you can see the script blocks within the html that define the templates. There is one with an {{outlet}} and an index template. If you look at js/app.js you will see that the IndexRoute returns an array of strings which are rendered into the index template. The templates use <a title="handlebars js template language" href="http://handlebarsjs.com">handlebars</a> which is similar to erb in rails but is contained within javscript &lt;script&gt; blocks with a type of &#8220;text/x-handlebars&#8221;. Unfortunately we don&#8217;t have the benefit of rails logging what is happening when we go to a url in our application but we can ask ember to tell us what route it is rendering, to do this we will change the main ember application javascript. Open up js/app.js in an editor and change App=Ember.Application.create() to</p>
<blockquote>
<pre>App=Ember.Application.create({
  LOG_TRANSITIONS: true
});</pre>
</blockquote>
<p>Log transitions will help us to see what the router is doing when we move from page to page. If you open up a browser console and reload the index page you will see that it says &#8220;Transitioned into &#8216;index&#8217;&#8221;</p>
<p>We will now add our own bits to the starter app. Start by removing the existing handlebars templates from index.html and add the one shown below. Remember to place it within the html &lt;body&gt; tag.</p>
<blockquote><p>&nbsp;</p>
<pre>&lt;script type="text/x-handlebars"&gt;
  &lt;body&gt;
    &lt;header&gt;
      &lt;h1&gt;Blog&lt;/h1&gt;
    &lt;/header&gt;
    &lt;div&gt;
      {{outlet}}
    &lt;/div&gt;
    &lt;footer&gt;
      &amp;copy;2013 Me.
    &lt;/footer&gt;
  &lt;/body&gt;
&lt;/script&gt;</pre>
<p>&nbsp;</p></blockquote>
<p>Within this script block we have defined a template which has type text/x-handlebars, this is the basic application template into which other templates will be rendered, as you saw with the index route earlier. Anything wrapped in {{ }} tells handlebars to do something. The <code>{{outlet}}</code> is similar to <code>&lt;%= yield %&gt;</code> in rails, the placeholder where other templates are rendered.<br />
We also need to create our application inside app.js. Remove the section with App.IndexRoute, leaving only the App definition with the LOG_TRANSITIONS we added</p>
<blockquote>
<pre>App=Ember.Application.create({
  LOG_TRANSITIONS: true
)};</pre>
</blockquote>
<p>We will start by defining a simple router, add the following to app.js</p>
<blockquote>
<pre>App.Router.map(function() {
});</pre>
</blockquote>
<p>and then populate it with a route</p>
<blockquote>
<pre>App.Router.map(function() {
  this.resource('posts');
});</pre>
</blockquote>
<p>Refresh the page and you will see that we have transitioned into index but there is nothing there except the header and footer text we specified. That is expected since we removed the index template, we will add them back during part 2. We can use App.Router.router.recognizer.names in the web console to see all the routes. It returns a js object within which all the current routes are show. Use it and you will see that we have the routes index and posts. Seems that it does not behave like you think it would in rails and only creates 2 named routes &#8216;index&#8217; and &#8216;posts&#8217; ie &#8216;/&#8217; and &#8216;/posts&#8217;. What we also need is /posts/:id. To do this we have to create a route for instances of a post.</p>
<blockquote>
<pre>App.Router.map(function() {
  this.resource('posts');
  this.resource('post', { path: '/posts/:post_id' } );
});</pre>
</blockquote>
<p>Again this doesn&#8217;t quite get us what we want and only gives us the &#8216;index&#8217;, &#8216;posts&#8217; and &#8216;post&#8217; routes which will work fine but we want member routes under &#8216;post&#8217; so that we can show, edit, delete etc. To begin with what we actually want is &#8216;index&#8217;, &#8216;posts&#8217; and &#8216;post.index&#8217;. &#8216;post.index&#8217; is &#8216;/posts/:post_id&#8217; which in ember terms is the equivalent of rails route &#8216;show&#8217;. We want a page which shows all posts and one which shows a single post. We need to add some more to the router for this.</p>
<blockquote>
<pre>App.Router.map(function() {
  this.resource('posts');
  this.resource('post', { path: '/posts/:post_id' }, function() {
  });
});</pre>
</blockquote>
<p>We have defined an inner function of the &#8216;post&#8217; resource where the member routes will be defined. You get &#8216;post.index&#8217; for free. To look at all the routes you have defined again use App.Router.router.recognizer.names in a browser console. We now have &#8216;index&#8217;, &#8216;posts&#8217; and &#8216;post.index&#8217;. We have some basic routes defined, now we need some UI magic. In <a title="Ember JS templates" href="http://dev.mygrid.org.uk/blog/?p=75">part 2</a> we will look at templates and handlebars along with the models, store and routes to hook them together.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=46</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Data consistency is everything</title>
		<link>http://dev.mygrid.org.uk/blog/?p=42</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=42#comments</comments>
		<pubDate>Tue, 24 Apr 2012 08:57:09 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[edina]]></category>
		<category><![CDATA[mapping]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=42</guid>
		<description><![CDATA[I have recently been working with some social scientists on estimating the prevalence of certain disabilities in the UK regions using census, health survey for england and R. One of the aims is to show the stats on a map. &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=42">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have recently been working with some social scientists on estimating the prevalence of certain disabilities in the UK regions using census, health survey for england and R. One of the aims is to show the stats on a map. Edina&#8217;s <a href="http://thematic.edina.ac.uk/thematic/map">thematic mapping service</a> helps here. However I was having difficulty with inconsistencies in the UK district classifications. Why is the source data for each of the countries in the UK (available through edina again) published in a slightly different format:</p>
<p><strong>Scotland:</strong></p>
<p>&#8220;COUNCIL_AREA&#8221;,&#8221;NAME&#8221;,&#8221;ONS_CODE&#8221;</p>
<p>&#8220;01&#8243;,&#8221;Aberdeen City&#8221;,&#8221;QA&#8221;</p>
<p><strong>England/Wales:</strong></p>
<p>COUNTY_CODE_2001<span> </span>DISTRICT_CODE_2001<span> </span>DISTRICT_NAME_2001</p>
<p>00<span> </span>AA<span> </span>City of London</p>
<p><strong>Northern Ireland:</strong></p>
<p>District,District Labels</p>
<p>95AA,Antrim</p>
<p>So, we have two in csv, one in tab, one which uses quotes around fields and headers, one which joins the codes into a 4 letter string and different orders in each file. How much time could we all save if the creators of such data talked to one another.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=42</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails and IIS on Windows 7</title>
		<link>http://dev.mygrid.org.uk/blog/?p=41</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=41#comments</comments>
		<pubDate>Fri, 16 Dec 2011 12:37:24 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=41</guid>
		<description><![CDATA[Here are the steps I needed to install ruby 1.8, rails 2.3, sqlserver to run our https://github.com/myGrid/methodbox codebase on a Windows 7 platform and run it all under IIS. It should also work for any rails 2 or 3 project.  &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=41">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here are the steps I needed to install ruby 1.8, rails 2.3, sqlserver to run our https://github.com/myGrid/methodbox codebase on a Windows 7 platform and run  it all under IIS. It should also work for any rails 2 or 3 project.  If you use rmagick or libxml-ruby then pay attention to the installing gems part for some dlls you need to install along with where to get them.</p>
<p>So, having tried various solutions involving fastcgi and url rewrite which I could not get to work on IIS 7.5 under Windows 7 I found <a title="Helicon Tech Zoo" href="http://www.helicontech.com/zoo" target="_blank">http://www.helicontech.com/zoo</a> . I&#8217;ve seen the people behind it on various other posts on msdn etc so there is some history of them working on IIS, fastcgi and url rewrite. In fact I think they have had a url rewrite product available for a number of years.</p>
<p>* Install Rails</p>
<p>1) Install the Web Platform Installer from http://www.microsoft.com/web/downloads/platform.aspx<br />
2) Add http://www.helicontech.com/zoo/feed as a new feed<br />
3) From the zoo tab select Blank Ruby on Rails Rails project and Ruby1.8 and click the install button. It will also install other dependencies.<br />
4) When installing the blank project it will pop up and ask you where to put it along with other required details like the name. Make a note of where the project lives since we need a couple of files from it.<br />
5) From the blank rails project we need the web.config files in the projects root and public directories.  Place these in the same place in your rails project directories.  To use Ruby1.9 we need to replace ruby.1.9.pipe in the web.config in the projects root directory with ruby.1.8.pipe. You may also have to add the path to ruby&#8217;s bin directory to your environment variables &#8211; C:\Ruby18\bin or C:\Ruby19\bin<br />
6) Ensure that the projects directories are writeable by the IIS_IUSRS user.<br />
7) Add the project to IIS with the project path pointing to the rails projects root directory (not public like you would with a rails project under apache).</p>
<p>* Install Git</p>
<p>This is used for version control and can be found on http://git-scm.com/ Install the version marked &#8216;Full installer for official Git for Windows 1.7.8&#8242; or similar (version name might be different).</p>
<p>* Install required gems (libxml and imagemagick specific instructions)</p>
<p>There are various 3rd party dependencies that the gems that MethodBox requires including imagemagick (ie. rmagick) and libxml-ruby. On windows this requires a little bit of user intervention during the install process. Go to http://www.imagemagick.org/script/binary-releases.php?ImageMagick=uteqfietdab37ghqrvfuvoul55#windows and download http://www.imagemagick.org/download/binaries/ImageMagick-6.7.3-7-Q16-windows-dll.exe<br />
Double click and go through the installer, selecting to install C and C++ header files and libraries from the additional options page<br />
add environment variable CPATH=\path\to\imagemagick\include and LIBRARY_PATH=\path\to\imagemagick\lib</p>
<p>There is a high chance that the libxml-2.2.dll needed for libxml-ruby is not present in the lib folder and will pop up an error.  The dll can be found in C:\Ruby18\lib\ruby\gems\1.8\gems\libxml-ruby-2.2.0-x86-mingw32\lib\libs\  Copy the libxml, iconv and zlib dlls and put in the C:\Ruby18\bin folder.</p>
<p>Note: If you are not using mysql then comment any mysql gem out of the  Gemfile. Otherwise the system may complain about libmysql.dll missing.  If you are using mysql you need to copy  the dll from the mysql/bin folder to the ruby lib folder.</p>
<p>* SQL server and rails</p>
<p>1) Find out your SQL server details. If your SQL server instance has not been allowed through the firewall then you need to find out its details: open up the sqlserver management console (which you can install along with sqlserver express via the Web Platform Installer &#8211; I recommend this way, downloading on its own and installing does not work correctly) and look at your db details.<br />
2) Set up a Data Source Name (DSN) for your ODBC connection.  This is not that well documented so you need to find the C:\Windows\sysWOW64 directory and start the odbcad32 programme.  Then you add a system DSN for your instance of sqlserver.<br />
3) Set up your rails projects database.yml as normal with the following records:</p>
<p>adapter: sqlserver<br />
mode: odbc<br />
dsn: sqlserverapp-dsn (the one you created earlier)<br />
username: user<br />
password: secret<br />
host: localhost (or whatever)</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=41</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby, Windows and RMagick</title>
		<link>http://dev.mygrid.org.uk/blog/?p=40</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=40#comments</comments>
		<pubDate>Thu, 24 Nov 2011 10:00:06 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[image magick]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rmagick]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=40</guid>
		<description><![CDATA[Been doing a lot of rails work on windows recently and ran into some issues that needed solved.  Just like on Unix, to get the RMagick gem working on a windows platform you need to install ImageMagick.  Go to http://www.imagemagick.org/script/binary-releases.php?ImageMagick=uteqfietdab37ghqrvfuvoul55#windows &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=40">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Been doing a lot of rails work on windows recently and ran into some issues that needed solved.  Just like on Unix, to get the RMagick gem working on a windows platform you need to install ImageMagick.  Go to http://www.imagemagick.org/script/binary-releases.php?ImageMagick=uteqfietdab37ghqrvfuvoul55#windows and download http://www.imagemagick.org/download/binaries/ImageMagick-6.7.3-7-Q16-windows-dll.exe</p>
<p>Double click and go through the installer, selecting to install C and C++ header files and libraries from the additional options page (this is very important)</p>
<p>Then add environmant variable CPATH=\path\to\imagemagick\include and LIBRARY_PATH=\path\to\imagemagick\lib</p>
<p>You can then &#8216;gem install rmagick&#8217; and it will build it using the native image magick libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=40</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sun/Oracle Java on Ubuntu</title>
		<link>http://dev.mygrid.org.uk/blog/?p=39</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=39#comments</comments>
		<pubDate>Mon, 04 Apr 2011 15:17:49 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[10.04]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[lucid lynx]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=39</guid>
		<description><![CDATA[Ubuntu Lucid Lynx (10.04) does not have the sun java repositories available by default.  You need to add them like this: sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner" Then update the packages available: sudo apt-get update Then you can install Sun&#8217;s &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=39">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ubuntu Lucid Lynx (10.04) does not have the sun java repositories available by default.  You need to add them like this:</p>
<p><code>sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"</code></p>
<p>Then update the packages available:</p>
<p><code>sudo apt-get update</code></p>
<p>Then you can install Sun&#8217;s (Oracles?) Java</p>
<p><code>sudo apt-get install sun-java6-jdk sun-java6-jre sun-java6-plugin</code></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=39</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bundler, OSX and the MysqlCompat::MysqlRes error</title>
		<link>http://dev.mygrid.org.uk/blog/?p=38</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=38#comments</comments>
		<pubDate>Fri, 25 Mar 2011 11:53:18 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[bundle]]></category>
		<category><![CDATA[bundler]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=38</guid>
		<description><![CDATA[If you get the uninitialized constant MysqlCompat::MysqlRes error when trying to run your Rails app all the evidence points to it being a 32 v 64 bit issue.  However, I had built mysql for the x86_64 architecture and the mysql &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=38">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you get the <em>uninitialized constant MysqlCompat::MysqlRes</em> error when trying to run your Rails app all the evidence points to it being a 32 v 64 bit issue.  However, I had built mysql for the x86_64 architecture and the mysql gem installed was also for 64 bits.  So why was I still getting this error.  It turns out that bundler was building the mysql gem in 32 bits.  OSX Snow Leopard ships with Ruby in a universal binary containing the ppc, i386 and x86_64 binaries and for whatever reason <code>bundle install</code> was using the 32 bit ruby and re-building everything even though I had the gems already installed in the system in 64 bit mode.  This could be because the user doing the building was 1) unprivileged and 2) using <code>bundle install \--path=vendor</code>.  Maybe bundler was picking the first version of ruby that was appropriate to the platform.  However, doing <code>bundle install \--deployment</code> also had the same issues. I have no idea why it was rebuilding gems that already existed on my system.  The way to get round it was to force bundler to build in 64 bits by using <code>env ARCHFLAGS='-arch x86_64' bundle install --path=vendor</code><br />
Maybe the best idea is not to use the Ruby that ships with OSX and build one appropriate to your environment in the first place.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=38</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tab navigation and tooltips</title>
		<link>http://dev.mygrid.org.uk/blog/?p=37</link>
		<comments>http://dev.mygrid.org.uk/blog/?p=37#comments</comments>
		<pubDate>Thu, 02 Sep 2010 10:31:44 +0000</pubDate>
		<dc:creator>Ian Dunlop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tab]]></category>
		<category><![CDATA[tabifier]]></category>
		<category><![CDATA[tooltip]]></category>

		<guid isPermaLink="false">http://www.mygrid.org.uk/dev/blog/?p=37</guid>
		<description><![CDATA[We use the tabifier javascript from barelyFitz in a few places in MethodBox.  However, I wanted it to have a different, more descriptive tooltip than the tab title.  The default code doesn&#8217;t seem to do this so I added a &#8230; <a href="http://dev.mygrid.org.uk/blog/?p=37">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We use the tabifier javascript from <a title="Barely Fitz tabifier" href="http://www.barelyfitz.com/projects/tabber/">barelyFitz</a> in a few places in <a title="MethodBox survey browsing and sharing" href="http://www.methodbox.org">MethodBox</a>.  However, I wanted it to have a different, more descriptive tooltip than the tab title.  The default code doesn&#8217;t seem to do this so I added a couple of little changes to make this happen.</p>
<p>You can see the complete file <a title="MethodBox tabifier code" href="http://code.google.com/p/methodbox/source/browse/trunk/methodbox/public/javascripts/tabber-new.js">here</a> but below is a quick synopsis of the changes:</p>
<p>added a boolean to keep track of whether you want a different tooltip than the tab title:</p>
<p><code> this.differentTooltip = true;</code></p>
<p>if this isn&#8217;t the behaviour you wanted then that&#8217;s ok:</p>
<p><code> if (!this.differentTooltip) {<br />
t.headingText = t.div.title;<br />
}<br />
</code></p>
<p>however, if the tooltip is to be different then make sure the<br />
link for the tab is correct:</p>
<p><code> if (this.differentTooltip) {<br />
DOM_a.title = t.tooltipText;<br />
} else {<br />
DOM_a.title = t.headingText;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://dev.mygrid.org.uk/blog/?feed=rss2&#038;p=37</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
