Chapter 10
Looks like I’m tackling shipping in this chapter.
Page 116. I need to add a “shipped_at” column to the orders table. So I open up create_db.rb and modify the create orders table code:
db.create_table(:orders,:name, :String,:email, :String,:address, :String,:pay_type, :String,:shipped_at, :Time)
Notice that the MySQL datatype datetime maps to the KirbyBase datatype :Time. I learned this lesson in an earlier chapter.
I now rerun create_db.rb to recreate the tables. As the book mentions, I’m tired of having to re-enter product info into the products table every time I re-create it. So, I’m going to follow the book’s lead and create a file called product_data.rb that I can run to repopulate the products table. The big difference is that my file will have Ruby code in it instead of SQL statements, since KirbyBase is pure-Ruby. Here’s what the product_data.rb file looks like:
require 'kirbybase'require 'time'db = KirbyBase.newproducts_tbl = db.get_table(:products)products_tbl.insert('Pragmatic Project Automation','A really great read!','/images/sk_auto_small.jpg',29.95,Time.parse('2004-12-25 05:00:00'))products_tbl.insert('Pragmatic Version Control','A really controlled read!','/images/sk_svn_small.jpg',29.95,Time.parse('2004-12-25 05:00:00'))
In line 2, I require ‘time’, so that I can use the Time.parse method to easily create Time objects. In line 4, I grab a handle to the products table so that I can easily reference it’s insert method. Notice, also, that since KirbyBase uses Ruby data types, I am passing it an actual Ruby Float object and a Ruby Time object.
I run product_data.rb and my products table is populated!
Page 117. The book creates a pending_shipping method in the Order model that will return all orders that have not been shipped yet. Here’s what the method in the book looks like:
def self.pending_shippingfind(:all, :conditions => "shipped_at is null")end
Instead of “null” KirbyBase uses Ruby’s nil object to signify what “null” means in other database management systems. Therefore, to rewrite the pending_shipping method so that KirbyBase can understand it, I create the method like so:
def self.pending_shippingfind(:all) {|rec| rec.shipped_at.nil?}end
Notice how we use Ruby’s nil? method and enclose the Ruby expression in a block.
Next, I create ship.rhtml.
Page 118. I create the partial template, _order_line.rhtml. I pretty up admin.rhtml.
Page 119. I refresh my browser and the “Orders to be Shipped” screen appears in all it’s glory.
Page 122 I implement the ship, do_shipping, and pluralize methods in admin_controller.rb. I add #mark_as_shipped to order.rb. I don’t need to change anything in these method. They work exactly the way they do in the book. I go back to my browser and mark one of the orders as shipped. The order disappears and the flash message says “One order marked as shipped”.
Just to be sure, I go open up orders.tbl. There, in the first record’s :shipped_at field, is “Wed Feb 22 15:25:44 EST 2006″. Ackbar’s still going strong!
On to the final chapter.
Assaph Mehr replied:
Actually you could have left the
:conditions => “shipped_at is null”
as is, and it would have been translated to
rec.shipped_at == nil
Not quite idiomatic Ruby, but it does the job. It goes this way because it is a two step process (IS -> == and NULL -> nil).
February 23, 2006 at 1:10 pm. Permalink.
houseonfire replied:
You are correct, with one small caveat. To get it to work, you have to make sure “is” and “null” are both upper case. So, the condition string would need to look like this:
“shipped_at IS NULL”
I think a simple change to the SQL_FRAGMENT_TRANSLATIONS regexp will fix this. I’ll email you a fix.
February 23, 2006 at 7:29 pm. Permalink.
chanel長財布 replied:
I have been surfing online more than 4 hours today, yet
I never found any interesting article like yours. It is pretty worth
enough for me. In my opinion, if all site owners and bloggers made good
content as you did, the internet will be
a lot more useful than ever before.|
I could not refrain from commenting. Perfectly written!
|
I’ll immediately snatch your rss as I can’t to find your e-mail subscription hyperlink or e-newsletter service.
Do you have any? Kindly allow me realize
so that I could subscribe. Thanks.|
It’s the best time to make some plans for the future and it is time to be happy. I’ve
read this post and if I could I wish to suggest you few interesting things or tips.
Perhaps you can write next articles referring to this article.
I wish to read even more things about it!|
It’s the best time to make some plans for the longer term and it’s
time to be happy. I’ve read this post and if I may just I want to recommend you few interesting issues or tips. Perhaps you can write next articles relating to this article. I desire to learn even more things approximately it!|
I have been surfing online more than 3 hours today, but I by no means found any fascinating article like yours. It’s pretty worth enough for
me. In my opinion, if all website owners and bloggers made excellent content material as you did, the web
shall be a lot more useful than ever before.|
Ahaa, its fastidious dialogue on the topic of this piece of writing at this
place at this web site, I have read all that, so at
this time me also commenting at this place.
|
I am sure this article has touched all the internet
visitors, its really really fastidious article
on building up new webpage.|
Wow, this post is pleasant, my sister is analyzing these kinds of things,
therefore I am going to inform her.|
bookmarked!!, I love your web site!|
Way cool! Some extremely valid points! I appreciate you penning this
write-up and also the rest of the site is also very good.
|
Hi, I do think this is an excellent website.
I stumbledupon it ;) I am going to revisit once again since i have book marked it.
Money and freedom is the best way to change, may you be rich and
continue to guide other people.|
Woah! I’m really loving the template/theme of this blog. It’s simple, yet effective.
A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appearance. I must say you have done a awesome job with this. Also, the blog loads super quick for me on Safari. Outstanding Blog!|
These are genuinely wonderful ideas in concerning blogging. You have touched some good factors here. Any way keep up wrinting.|
I enjoy what you guys are up too. Such clever work and reporting! Keep up the wonderful works guys I’ve added you guys to my blogroll.
|
Howdy! Someone in my Facebook group shared this site with us so
I came to check it out. I’m definitely loving the information. I’m bookmarking and
will be tweeting this to my followers! Terrific blog and
outstanding style and design.|
I like what you guys are usually up too. This kind of clever work and
coverage! Keep up the awesome works guys I’ve included you guys to my blogroll.|
Hey there would you mind sharing which blog platform you’re working with?
I’m looking to start my own blog soon but I’m having a difficult time
choosing between BlogEngine/Wordpress/B2evolution
and Drupal. The reason I ask is because your
layout seems different then most blogs and I’m looking for something completely unique. P.S Apologies for getting off-topic but I had to ask!|
Hey there would you mind letting me know which webhost you’re working with?
I’ve loaded your blog in 3 different browsers and I must say this blog loads a lot quicker then most. Can you suggest a good internet hosting provider at a fair price? Cheers, I appreciate it!|
I love it when individuals come together and share thoughts. Great website, continue the good work!|
Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how could we communicate?|
Hey just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Internet explorer. I’m
not sure if this is a formatting issue or something
to do with internet browser compatibility but I thought I’d post to let you know. The layout look great though! Hope you get the issue fixed soon. Cheers|
This is a topic which is near to my heart… Thank you! Exactly where are your contact details though?|
It’s very easy to find out any matter on web as compared to books,
as I found this post at this web page.|
Does your blog have a contact page? I’m having a tough time locating it but, I’d like to send you an e-mail.
I’ve got some ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it develop over time.|
Hola! I’ve been reading your website for a while now and finally got the bravery to go ahead and give you a shout out
from Dallas Tx! Just wanted to tell you keep up the excellent work!
|
Greetings from Los angeles! I’m bored to death at work so I decided to browse your website on my iphone during lunch break. I enjoy the knowledge you present here and can’t wait to take a look when I get home.
I’m shocked at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .
. Anyways, excellent blog!|
Its like you learn my mind! You appear to grasp a lot about this,
such as you wrote the ebook in it or something. I think
that you just could do with a few percent to
drive the message home a little bit, however other than that, that is excellent blog.
A great read. I will certainly be back.|
I visited several sites but the audio quality for audio songs present at
this website is genuinely superb.|
Howdy, i read your blog from time to time and i own a similar one and i was just
wondering if you get a lot of spam feedback? If so how do you reduce
it, any plugin or anything you can recommend?
I get so much lately it’s driving me mad so any assistance is very much appreciated.|
Greetings! Very useful advice in this particular article! It is the little changes that make the largest changes. Thanks a lot for sharing!|
I absolutely love your site.. Pleasant colors & theme. Did you build this amazing site yourself? Please reply back as I’m attempting to create my own site and would like to find out
where you got this from or exactly what the theme is named.
Appreciate it!|
Hi there! This article couldn’t be written much better! Reading through this article reminds me of my previous roommate! He continually kept talking about this. I most certainly will send this article to him. Fairly certain he’s going to
have a very good read. I appreciate you for sharing!
|
Incredible! This blog looks just like my old one! It’s on a entirely different subject but it has pretty much the same page layout and design. Great choice of colors!|
There is certainly a great deal to find out about this topic. I like all of the points you’ve made.
|
You’ve made some decent points there. I checked on the net to learn more about the issue and found most individuals will go along with your views on this web site.|
What’s up, I read your blogs on a regular basis. Your humoristic style is awesome, keep it up!
|
I just could not go away your site before suggesting that I really enjoyed
the standard information an individual supply in your guests?
Is going to be back ceaselessly to inspect new posts|
I want to to thank you for this excellent read!! I absolutely
enjoyed every little bit of it. I have got you saved as a favorite to check out new things you post…|
Hi there, just wanted to tell you, I loved this post.
It was helpful. Keep on posting!|
I comment each time I especially enjoy a article on a site or I have something to add to the conversation.
It is a result of the fire displayed in the article I read.
And after this post Chapter 10 | Is your house on fire,
Clark?. I was excited enough to drop a leave a responsea response ;) I actually do have a
couple of questions for you if it’s okay. Is it simply me or do some of the responses appear like written by brain dead folks? :-P And, if you are writing at additional online sites, I would like to follow you. Could you make a list the complete urls of your community sites like your linkedin profile, Facebook page or twitter feed?|
Hello, I enjoy reading all of your article post. I wanted to write a little comment to support you.|
I always spent my half an hour to read this webpage’s
posts daily along with a mug of coffee.|
I all the time emailed this website post page to all my associates, because if
like to read it after that my friends will too.
|
My coder is trying to persuade me to move to .
net from PHP. I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using Movable-type on several websites for about a year and am anxious about
switching to another platform. I have heard fantastic things
about blogengine.net. Is there a way I can import all my wordpress content into it?
Any kind of help would be greatly appreciated!
|
Hi! I could have sworn I’ve visited this blog before but after looking at a few of the articles I realized it’s new to me.
Anyways, I’m certainly delighted I found it and I’ll be book-marking it and checking back frequently!
|
Terrific work! This is the kind of information that are meant to be shared around the web.
Shame on the search engines for no longer positioning this post higher!
Come on over and seek advice from my web site .
Thanks =)|
Heya i’m for the first time here. I came across this board and I find It truly useful & it helped me out much. I hope to give something back and aid others like you aided me.|
Greetings, I believe your blog could possibly be having browser compatibility issues. When I look at your site in Safari, it looks fine however, when opening in I.E., it’s
got some overlapping issues. I just wanted to give you a quick heads up!
Other than that, excellent site!|
Someone essentially lend a hand to make severely articles I would state.
This is the very first time I frequented your website page and to
this point? I surprised with the analysis you made to make this actual submit
amazing. Magnificent process!|
Heya i’m for the first time here. I came across this board and I find It really useful & it helped me out much. I’m hoping
to provide one thing back and help others such as you helped me.
|
Hi! I simply wish to offer you a big thumbs up for your
excellent information you’ve got here on this post. I am coming back to your site for more soon.|
I always used to study post in news papers but now as I am a user of internet therefore from now I am using net for articles, thanks to web.|
Your mode of explaining the whole thing in this paragraph is in fact good, every one can effortlessly know it, Thanks a lot.|
Hello there, I found your web site by the use of Google even as looking for a related matter, your web site got here up, it looks great. I have bookmarked it in my google bookmarks.
Hi there, just changed into aware of your blog thru Google, and located that it’s truly informative.
I am gonna watch out for brussels. I will appreciate when you
proceed this in future. Numerous other people can be
benefited from your writing. Cheers!|
I’m curious to find out what blog platform you are using? I’m experiencing some minor
security problems with my latest blog and I would like to find
something more risk-free. Do you have any solutions?|
I’m extremely impressed with your writing skills and also with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today.
|
I am really inspired together with your writing talents and also with
the format in your blog. Is that this a
paid subject matter or did you customize it yourself?
Either way keep up the excellent high quality writing, it’s uncommon to look a great weblog like this one today..|
Hi, Neat post. There’s an issue along with your website in web explorer, could check this?
IE nonetheless is the market leader and a huge element of other people will leave out your fantastic writing
due to this problem.|
I’m not sure where you are getting your info, but great topic. I needs to spend some time learning more or understanding more. Thanks for magnificent information I was looking for this information for my mission.|
Hi, i think that i saw you visited my weblog so i came to “return the favor”.I’m trying to
find things to improve my website!I suppose its ok to use
some of your ideas!!\
May 28, 2013 at 11:43 pm. Permalink.