Monday, October 24, 2011

Autumn short vacation 2011

I take a autumn vacation, so I suspend posts and comments to this blog for a moment. Resume will be November 4, 2011.

Friday, October 21, 2011

make unobtrusive CoffeeScript on AWDwR 4th beta chapter15

On Agile Web Development with Rails 4th edition beta chapter15 (Internationalization), there is one more stuck point not-related with internationalization. In this chapter, JavaScript sample is not unobtrusive one. So I try to rewrite the sample with unobtrusive CoffeeScript.

application.js and application.html.erb

In this tutorial, we should use CoffeeScript only store.js.coffee. So we can omit to use another *.js.coffee files.
  1. In application.js file, delete the line //= require_tree ..
  2. In application.html.erb file, add the line <%= javascript_include_tag "store" %>.

make unobtrusive

In store.js.coffee, write the code for erase submit button and execute the action when drop down list is changed.
$ ->
  $('.locale input').hide()
........
$ ->
  $('#set_locale').change ->
    $(this).parent('form.locale').submit()
so that we just write the drop down list in layouts/application.html.erb like below:
    <%= form_tag store_path, class: 'locale' do %>
      <%= select_tag 'set_locale', options_for_select(LANGUAGES, I18n.locale.to_s) %>
      <%= submit_tag 'submit' %>
    <% end %>

Tuesday, October 18, 2011

Addenda for AWDwR 4th beta chapter15

Agile Web Development with Rails 4th edition beta has a quality almost like final version. But, chapter15 (Internationalization) just has beta one. There are some stuck points. So I try to explain these points.

Configure default locale and available locales

In this book, author creates the file config/initializers/i18n.rb and configure default locale and locales for drop down list in this file. But, there are two better ways:
  1. This sample does not explain the code for available locales.
  2. There are some definitions for locale in config/application.rb file.
So that we should write below in config/application.rb file, not config/initializers/i18n.rb file:
# -*- coding: UTF-8 -*-
........
LANGUAGES = [
  ['English', 'en'],
  ['日本語'.html_safe, 'ja']
]


module Depot
  class Application < Rails::Application
........
    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    config.i18n.default_locale = :en
    config.i18n.available_locales = LANGUAGES.map(&:last)

........
  end
end

default_url_options in controller

In this book, method default_url_options is inplemented in ApplicationController class. But, this brings two troublesome points.
  1. default_url_options would take an optional argument for hash.
  2. This works when server running or functional test running, but does not when integration test running.
So that we re-write these:
application_controller.rb
  def default_url_options(options={})
    options.merge({locale: I18n.locale})
  end
In each integration tests
  def setup
    app.default_url_options = { locale: I18n.locale }
  end

Saturday, October 15, 2011

Rails 3.1.1 never depends on bcrypt-ruby, but must be required.

One week ago, Ruby on Rails 3.1.1 has been released. Since this release, rails never depends on bcrypt-ruby. But, when you use some functions related with encryption, you need to choice from some encryption gems.

For example, if you want to use has_secure_password, you should write onto Gemfile like below:
gem 'bcrypt-ruby', '~> 3.0.0'

Wednesday, October 12, 2011

MySQL Connector/Net 6.4.4 has been released

In two weeks ago, MySQL Connector/Net 6.4.4 has been released(Check change log).

You may think this release is small bug-fix one. But, for ASP.NET MVC3 / EntityFramework4 developer, this contains big change. Since this release, "Code first" function runs correctly with PluralizingTableNameConvention. So you don't have to remove this convention like this post anymore!

Monday, October 10, 2011

Ruby community announces 1.8.x will be discontinued

Ruby community announces that Ruby 1.8.7 will be stopped developing in June 2012 and will be discontinued including any bug-fixes in June 2013.

Plans for 1.8.7

I strongly welcome this decision. And I also hope for Ruby Association that they will change their Ruby Certification from Ruby 1.8.7 tests to ruby 1.9.3 tests!

Friday, October 7, 2011

R.I.P. Steve Jobs

Thank you, Steve. I use OS X Lion on my Macmini, and Windows 8 DP on its Bootcamp comfortably.

Tuesday, October 4, 2011

Two .js templates in Rails 3.1

In Rails 3.1, there are two JavaScript templates - the one is 'app/views/**/*.js.erb', the other one is 'app/assets/javascripts/*.js.coffee'. What are these? And how different are these?

In short, 'app/views/**/*.js.erb' is bare jQuery with ERb template, and 'app/assets/javascripts/*.js.coffee' is CoffeeScript file.

In more detail, 'app/views/**/*.js.erb' is written for the response of Ajax request, both with bare jQuery and with ERb. 'app/assets/javascripts/*.js.coffee' is written for another scripts with CoffeeScript when the page is loaded. And then, 'app/assets/javascripts/*.js.coffee' is compiled to jQuery by server-side JavaScripts (e.g. node.js).

Saturday, October 1, 2011

Where will Qt go? (reprise)

10 months ago, I wrote the article: phosphorescence: Where will Qt go?. In today, despite the fact that Qt 4.7.4 and QtCreator 2.3.1 had been released, Qt again encounters the pinch to be discontinued.

The reason is that Meego is discontinued because Intel decide to marge Meego to Samsung's LiMo, and rename these to Tizen. Tizen announces they recommand to use HTML5 as mobile application platform, not any native applications include Qt.

I agree that the future mobile application platform will be HTML5. And IMO, Qt should go back to just be a library for KDE.