Tuesday, March 30, 2010
Social Networking
Friday, February 19, 2010
Practicing Hacking
Saturday, January 9, 2010
Self learning
Self learning has been challenging. Building my blog website application from scratch has been fun but has not been the smoothest experience. I know what I want to implement and need to work to implement the features. The problem is that the work schedule is in my head and not written down. My focus is jumping from one thing to another thing. I'll be working on the layout of the comments and notice something in the comment form I want to improve and switch jobs. And neither one gets fixed. I will be figuring out a schedule of work to do and follow it.
Tuesday, January 5, 2010
Adding Date and Time to my Rails Blog App
For my blog posts and comments I wanted to display the date and time. Fortunately, the models automatically add the attribute created_at of datetime during the migration to the database. This allows me to just call the created_at attribute from the posts and comments table to display them after they have been created.
I got my first problem when I added it to my view. It appeared as 2009-12-14 08:25:51-1000. That's not what I wanted. I wanted December 14th, 2009 8:25AM. And this gave me another problem, the time was 10 hours off. I wanted Hawaii time so it should have been 2009-12-13 22:25:51-1000.
After a lot of searching I was able to piece together a solution. I have rails 2.3.3.
To format date and time I modified config/enviroment.rb. Looking at this file I found config.time_zone = 'UTC'. I didn't know what UTC was but above it had Run "rake -D time" for a list of tasks for finding time zone names. So I ran 'rake -D time' in my terminal and was given 'rake time:zones:local' which I ran and was given Hawaii as my time zone. So I changed config.time_zone = 'UTC' to config.time_zone = 'Hawaii'. This gave me my date and time but not the right format.
I wanted December 14th, 2009 8:25AM. To get this I had to create my format. I eventually found rails module for conversions. I then had to figure out what %Y-%m-%d meant. When I found the meaning I wrote the code below to display my date and time format. I also found to get 1 to display as 1st, 2 as 2nd, 14 as 14th, 23 as 23rd I had to add ordinalize to the day.
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:time => '%I:%M%p',
:date => lambda { |time| time.strftime("%B #{time.day.ordinalize}, %Y") }
)
Format Meaning
%a The abbreviated weekday name (“Sun'’)
%A The full weekday name (“Sunday'’)
%b The abbreviated month name (“Jan'’)
%B The full month name (“January'’)
%c The preferred local date and time representation
%d Day of the month (01..31)
%H Hour of the day, 24-hour clock (00..23)
%I Hour of the day, 12-hour clock (01..12)
%j Day of the year (001..366)
%m Month of the year (01..12)
%M Minute of the hour (00..59)
%p Meridian indicator (“AM'’ or “PM'’)
%S Second of the minute (00..60)
%U Week number of the current year, starting with the first Sunday as the first day of the first week (00..53)
%W Week number of the current year, starting with the first Monday as the first day of the first week (00..53)
%w Day of the week (Sunday is 0, 0..6)
%x Preferred representation for the date alone, no time
%X Preferred representation for the time alone, no date
%y Year without a century (00..99)
%Y Year with century
%Z Time zone name
%% Literal “%'’ character
In my view I added:
%= comment.created_at.to_s(:date) %
%= comment.created_at.to_s(:time) %
Now every post and comment has a correct date and time.
Thursday, December 17, 2009
Keola's Blog Application
For the past 16 days I’ve been hacking away on my blog application. My goal is to go from development to production. I want to get version 1.0 online by February 1st. I’m not quite sure what’s involved in taking a website public, but I am going to find out.
The site will be a two-column layout containing a header, navigation, content, sidebar, and footer. The navigation bar will have a home, about, contact, and blog page.
The blog engine is similar to the “creating a weblog in 15 minutes with Rails 2” screencast with a few minor tweaks. I added a few more attributes to the comment model to get a name, email, and website.
I also am building this application without using the scaffold to generate things. I want to understand the Rails convention. I want to fill out the controllers, views, routes and whatever else is needed. It’s running, so I’ve been pretty good about adding what is needed.
The past couple weeks have been fun. I’ve gotten further along then I planned. Everything is flowing. Next I will share some things I discovered.
Tuesday, December 1, 2009
Taking Action - Start to Finish
Imagining something you might like to have or do is a dream. A dream written down and clearly visualized is a goal. A tangible, measurable step written down and committed to is an action. You will not achieve a dream if you don't systematically work through the actions that lead to the goals that lead to the dream.
It's easy to get passionate about setting goals. We all get excited about our dreams. Taking consistent action on them on a daily basis until they are done is another story. How do we stay motivated with the same passion and excitement to follow through on the everyday tasks required to achieve the goals? How do we overcome any obstacles that occur?
Whenever we conceive the goals we want to achieve, we each enter our own process to accomplish these goals. My process involves imagining my goal as a finished product, researching and planning by gathering information to be prepared to work on the goal, and taking action to achieve the goal while maintaining the passion and self-discipline to follow through to the end result.
I have noticed that I easily get distracted and stuck in the researching and planning phase. I'm always looking for more and more information, but rarely implement what I've already learned. I am acknowledging that there are profound barriers between reading and DOING. I know that the solution isn’t “more,” but actually using the knowledge I've gained. I need to get to the action phase sooner. FAILURE is OK! I'll be learning while doing.
After taking action there is always an obstacle or two that try deter you from reaching your goal. At this point it becomes difficult and the excitement fades. This is when the self-discipline needs to kick in. I use my ability to be resourceful and work on solving the obstacle. If I'm having trouble figuring out how to overcome the obstacle, I seek out help. Two people are better then one and three people are better then two.
Today is the day I begin taking action. I've been learning Rails for a couple months and am still researching and planning. All I've been doing is reading up on Rails, CSS, and XHTML as well as following a bunch of tutorials. I haven't even started my own application. I've worked on a store application which had a buyers side with a shopping cart and a sellers side to handle the products and sales. I worked on a digg like application where users could submit articles and vote on them and view the most popular ones. I've done many different blog applications. And many more tutorials. Today I start hacking on my applications and less on tutorials. Maybe even find someone else's and contribute to it.
My dream is to create a website with all my web applications. My first goal is to create a blog for my website similar to the ones I read everyday. My actions will be to build the blog beyond what the tutorials teach.
Wednesday, November 11, 2009
Rails MVC
- The browser, on the client, sends a request for a page to the controller on the server.
- The controller retrieves the data it needs from the model in order to respond to the request.
- The controller hands the retrieved data to the view.
- The view is rendered and sent back to the client for the browser to display.
- improves scalability
- make maintenance easier
- promotes reuse