Contents
With Mack 0.6.0 quite a few things have changed under the covers, so here is your official guide to upgrading your existing 0.5.x Mack app to the latest and the greatest! This is not a full list of features available in this release, but rather an upgrade guide.
Some simple clean up
config/thin.ru and config/thin.yml are no longer needed by rake server. You can safely delete them if you'd like.
Code changes
Rakefile
Update your Rakefile to use the latest version of Mack. In your Rakefile you'll see a line similar to this:
gem 'mack', '0.5.5.4'
change that to use whatever version of the mack gem you've just downloaded, ie:
gem 'mack', '0.6.0'
Controllers/Views
Before a controller would look something like this:
class MyController < Mack::Controller::Base # action code omitted... end
Now controllers should look like this:
class MyController include Mack::Controller # action code omitted... end
Controllers now include Mack::Controller instead of subclassing Mack::Controller::Base.
Previously request parameters could be accessed like this:
params(:id)
Now they use a Hash-like syntax:
params[:id]
Support for HAML and Markaby is no longer included, by default, in the Mack 'core' code. Please use the mack-haml and mack-markaby gems.
Helpers
Some changes have happened in the land of helpers. First ApplicationHelper is now deprecated. For the time being this module will still be loaded in views, but it is no longer loaded into ANY controllers.
The Mack::ViewHelpers module is meant for adding view level modules. The Mack::ControllerHelpers module is meant for adding controller level modules.
View Helpers
Any modules under Mack::ViewHelpers will automatically be included into all views:
module Mack module ViewHelpers module MyHelpers # methods here end end end
Controller Helpers
In order for a controller helper module to be included into a controller it needs to following the naming convention of Mack::ControllerHelpers::<controller_name>. Example:
class MyController include Mack::Controller end module Mack module ControllerHelpers module MyController # methods here end end end
All the methods in Mack::ControllerHelpers::MyController will be included as protected methods into the MyController class. This also works with nested controller names:
class Admin::UsersController include Mack::Controller end module Mack module ControllerHelpers module Admin module UsersController # methods here end end end end
Models
If you are using ActiveRecord, nothing has really changed.
If you are using DataMapper, then hold on to your hats! Mack now uses DataMapper 0.9.2 instead of 0.3.2. What does this mean for you, well, it means that you'll have to update your DataMapper models, and any model code you have in places like controllers, migrations, etc... to use the new DataMapper API. For information on this visit http://www.datamapper.org. It is definitely out of the scope of this wiki to explain all the changes DataMapper has gone through from 0.3.x to 0.9.x
Testing
In Mack 0.6.0 the default testing framework is now RSpec. If you would like to continue using Test::Unit::TestCase, that's just great, but you'll need to configure your app to use it. First in your Rakefile add the following line:
alias_task :default, "test:test_case"
This will make the default Rake task one that will test your app using Test::Unit::TestCase. The only other step to making sure you're using the right testing framework is to go into your config/app_config/default.yml file and add the following line:
mack::testing_framework: test_case
This makes sure that all generated tests will be generated using your testing framework.
Configuration
If you're using Mack::Configuration.root or Mack::Configuration.env anywhere in your app, you'll need to stop doing that. Instead you can now use Mack.root and Mack.env. This makes your code cleaner and easier to use. Also, if you are using any of the other methods on Mack::Configuration such as public_directory or views_directory, those are now gone to. Please use the mack-paths gem to get similar results.
The MACK_DEFAULT_LOGGER constant is no longer available. Please use Mack.logger from now on.
ENV["_mack_root"] and ENV["_mack_env"] are longer used. Please use ENV["MACK_ROOT"] and ENV["MACK_ENV"]
No comments yet