Finally got some time to put here some notes for migrating DM from 0.9 to 0.10.
1. Errors. (That means you must fix)
1.1 options[:default] must not be nil
property :customer_address_id, Integer #, :default => nil
1.2 options :nullabe are unknown
property :deleted, Boolean, :field => 'deleteflag', :default => false #, :nullable => false
1.3 +options[:order]+ entry "po.closed_date.desc" does not map to a property in PurchaseOrderLineItem
order_by = [DataMapper::Query::Direction.new(PurchaseOrder.properties[:closed_date], :desc)]
result = PurchaseOrderLineItem.first(:deleted => false, :cb3_id => cb3_id, 'po.deleted.eql' => false, 'po.completed.eql' => 'yes', :order => order_by)
1.4 For composite keys
(e.g. when you do a migrate!)
property :user_id, Integer, :key => true, :nullable => false
property :role_id, Integer, :key => true, :nullable => false
2. Deprecated:
2.1 Integer with explicit :serial option is deprecated, use Serial instead
property :id, Integer, :key => true, :serial => true, :field => 'unitsindex'
property :id, Serial
2.2 +options[:class_name]+ is deprecated, use :model instead
belongs_to :customer_address, :class_name => "CustomerAddress", :child_key => [:customer_address_id, Integer]
2.3 explicit use of 'in' operator is deprecated
belongs_to :order, :model => 'Order', :child_key => [:order_id, Integer], :order_type.in => ['O', 's', 'w'], you can use
:order_type => ['O', 'S'] instead.
3. Others
model.new_record? now model.new?
model.update_attributes now model.update
Oct 18, 2009
Sep 14, 2009
Merb - a bug for merb router
You can not include a number(0-9) in your controller's name if you use it with nested routes. e.g.
Here is the quick fix:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :ordering do |order| | |
order.resources :codebook2s do |cb2| | |
cb2.resources :codebook2_line_items | |
end | |
... | |
... | |
end |
Here is the quick fix:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# merb-core-1.0.9/lib/merb-core/dispatch/router/route.rb | |
- SEGMENT_REGEXP_WITH_BRACKETS = /(:[a-z_]+)(\[(\d+)\])?/ | |
+ SEGMENT_REGEXP_WITH_BRACKETS = /(:[a-z0-9_]+)(\[(\d+)\])?/ |
Aug 21, 2009
_why?
It really doesn't matter what his name is, what I know is I read his book, use his projects and admired him.
Be good - Why The Lucky Stiff.
Be good - Why The Lucky Stiff.
Aug 17, 2009
Vim and CTaglist plugin
My ctaglist plugin stopped working after I migrated to my new MacBook Pro 13". After playing with it for a few minutes, I realized that my default ctags cmd is not correct. To have your ctaglist working, you have to use Exuberant Ctags. I am hoping this could save you some time for looking for the answer.
$> wget http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz
$> tar zxvf ctags-5.8.tar.gz
$> cd ctags-5.8
$> ./configure && make && sudo make install
You probably have to copy it over the old one if you not set the $PATH on you Mac( there is a ctags under /usr/bin)
$> sudo cp ctags /usr/bin/.
That's it, start you Vim, you are ready to go.
$> wget http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz
$> tar zxvf ctags-5.8.tar.gz
$> cd ctags-5.8
$> ./configure && make && sudo make install
You probably have to copy it over the old one if you not set the $PATH on you Mac( there is a ctags under /usr/bin)
$> sudo cp ctags /usr/bin/.
That's it, start you Vim, you are ready to go.
Aug 10, 2009
Render without calling the controller's action in Merb
I was working on a Merb project in the company, I found a common request is generate the report to view in the browser and also send the report as an attachment of an email in a cron job. Usually I have to do two parts of job, one is for the regular MVC parts to get the report in a browser. Then I have to generate the report and write it a file(html, text or pdf). Then send it out later. As you might see, there is a duplication here, I have to design the report twice. This really bothered me, why can't I just re-use the view templates which is used in the MVC. After poking around the merb-core source files, it turns out pretty easy to do that:
This is another reason I love Merb.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_daily_pos_report | |
# create a fake request | |
fake_request = Merb::Request.new({}) | |
# init the controller | |
controller = Purchasing::Reports.new(fake_request) | |
# gets all the pos created on today | |
pos = PurchaseOrder.all(:deleted => false, :po_date => date) | |
results = "No purchase orders created on #{date}" | |
if pos.size > 0 | |
## set the instance varialbe for the html.erb, :@pos see report/deaily_pos.html.erb | |
controller.instance_variable_set(:@pos, pos) | |
# gets the html string | |
results = controller.render :_daily_pos_results, :layout => :email | |
end | |
# if you want to re-use the logic in controll, you have to use _dispatch | |
# but this is not a good solution, you have embed in some extra logic to | |
# handle the render method in controller, the best way to re-use the logic | |
# in controller is to move the logic out of controller, put it some services | |
# layer, then you can re-use it. | |
# result = controller._dispatch(:daily_pos) | |
file = purchasing_dir + "/#{date}.html" | |
File.open(file, 'w') {|f| f.puts results} | |
file | |
end |
This is another reason I love Merb.
Aug 4, 2009
Enable/Disable bluetooth via cmd line
Since I got my new MacBook Pro 13", I found I constantly lost the connection with my bluetooth devices, like mouse or keyboard. It is so annoying that I have to reach my touch pad to disconnect the devices and re-connect them from the status bar or system preference. You'll know what I am talking about if you have the same problem as what I have. It is pretty pain.
Today, I found a command line tools for you to enable or disable the bluetooth, it is so handy. I just love it. Here is the link for blueutil.
Now, I can just issue the command: blueutil off and blueutil on, I am back on track again.
Today, I found a command line tools for you to enable or disable the bluetooth, it is so handy. I just love it. Here is the link for blueutil.
Now, I can just issue the command: blueutil off and blueutil on, I am back on track again.
Subscribe to:
Posts (Atom)