Okay, this may be the end of the long ass blogs that I'll be doing for this series. Most of the stuff after will be controller and UI related stuff.
But on part IV, we were talking about how to paginate with will_paginate. But we did not cover a login ONLY viewing their assigned-to projects. And here's how you do it. In AAA we have a current_user item that keeps track of the current user - We will take advantage of that. So check this out
With that simple change, you will only see the first two projects assigned to you!
Semi-Conclusion
I can't believe that building a website would be this ezed! Ruby & RoR is a framework that could not be compared with any programming technologies that I have used so far.
For those people who were curious, I used:
- TextMate **Highly Recommended
- iTerm
- macports
- Macbook Pro 1st get
- MySql
20070727
Jonas' Crazy Adventures in RoR - Part V - The Red thing Goes to my Wrist Watch... Oops!
20070726
Jonas' Crazy Adventures in RoR - Part IV - Test Data, will_paginate, Page Security
Okay, now we have a semi-well built model, let's see some UI action shall we? It won't be as fancy as you may think, but we're only focusing on the functionality right now and all that good stuff. in part deuce of the jonas series, we covered how to create a login acount using Acts as Authenticated (AAA). So that pretty much means that we have a user in the DB.
How do we verify this? script/console ofcourse! Below is a screenshot on how to verify if I have anything on my users table.
As you can see we have the one record - The account we made back in the days.
So let's go create some test data shall we? Again, I will be using the script/console style to insert my data... I'm going to create three new projects, and the first two will be assigned to the only user.
Here's how you do it:
Project.create :name => 'First Project', :description => 'This is my first project', :start_date => Date.today
Assignment.create :user_id => 1, :project_id => 2
Project.create :name => 'Second Project', :description => 'This is my second project', :start_date => Date.today
Assignment.create :user_id => 1, :project_id => 1
Project.create :name => 'Third Project', :description => 'This is my third project', :start_date => Date.today
Now let's check the database to show that I ain't bullsh*ttin'
Again, I just wanna let you guys know that I am intentionally making "Third Project" not assigned to any user. What I want to later is for the current user to be able to view his assigned projects.
Wait a sec. Jonas, I'm assuming u cannot add the same user to the same project more than once - How are you handling this?
Check this out suckah!
I want to see some UI action!!!!
I am going to cheat... I will be using script/generate scaffolding to generate my UI... But hey, at least I won't be coding a lot of stuff! The only difference is that I will be using a different method of pagination. I will be using will_paginate from errtheblog.
Lets just run our page for now, and see what we have:

Yay! we have a page! I will create 4 more test data to see the pagination stuff, and we will have 7:


Not bad, it works... but lets take a look at the list method that does the pagination stuff

"
You will notice that it returns two items! Soo ghetto! After talking with sideline. he pointed me to a rails cast about pagination found here. That will be the "new" way of pagination because in Rails 2.0 they will get rid of the ghetto-classic paging.
note: I semi-like will_paginate. the thing I don't like is that my model knows the implementation of paginate. If i used a presentation layer that handles the pagination, it would be better...
So what do we have to change?
list.rhtml, & product_controller.rb in the list method. Check out the before and after shots of the changes:
list.rhtml before

list.rhtml after

def list before

def list after

Not much change so it's all good!
Page Security
I will cover it briefly. Basically right now, we have a login page that does nothing, and our projects can be viewed by anyone. What we want to do is implement AAA's security stuff on our new project controller and here's how you do it:

That frikken ezed! now your anyone accessing project controller pages are required to login if they haven't yet.
This is jonas saying "alll right!"

Next time I will cover displaying only the projects a user is assigned to after login.
20070725
Luxuries of Riding Single Track

Finding porn mags. left by some bum/12 year old kid/perv to be viewed by mtb'ers! I'm the one on the Surly 1x1
p.s. If you notice I blog a lot... I'm f*cking bored @ work!
Jonas' Crazy Adventures in RoR - Part III - Migration Files & Models/Domain Objects
After the ezed stuff like login and creating your idea, now time to implement some ish...
So what did I do first? Create the model!
Step 1
below is a screen that I used to create my models/domain objects simply by bustin script/generate model <model_name>
once that is done, it will create a bunch of files... what we need to look for is the NNN_create_
now all you need to to create your fields
What I noticed is that there is no way by default to create your foreign keys on your migration file by default, you either have to (1)call the execute method I.E. "execute 'alter table....'" or (2)download a gem that does it for you. It looks like in rails development, all the relationships are built through your models/domain objects.
Step 2
Once you have finished creating your migration files time for the domain objects.
So lets start with the crazy ones... User, Assignment, & Project.
Before we begin check out the the relationship between user & project
You will notice we're busting a many to many relationship with users & projects through assignments.
This is how you implement the relationship in rails
and
once that "hard" part is done, everything else is ezed!
here's the most code I have done so far on my domain object
Well that's it for now... Stay tuned for testing the domain objects!
20070724
Jonas' Crazy Adventures in RoR - Part II - The Login
I know, I showed some ghetto ERD skillz on part 1, but I would like to try out some of the gems out there that has a pimp implementation of user authentication.
I talked to sideline and the semi-hottest .rb developer in cowtown, and they recommended Acts as Authenticated. So I'm trying it...
So far, not so bad... Installing it was cakes script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
then
script/generate authenticated user account
then
update your database.yml with the proper credentials to your db
then if you're using mysql
mysqladmin -u root -p create <database name>
then
rake db:migrate
if all goes well, your iTerm should look like:
also, it will create a "Users" table on your database
So now what?
Check out what you created! goto your browser and type: http://localhost:3000/account/index
and you will see a signup page

once you register, you will see..

what the hell is that???
looking @ the account_controller.rb file, especially the index method it does some logic... check you the screenshot:

also, check out
<project>/app/views/account/index.rhtml... there it is! that weird poem... get rid of that, and put something that makes sense... for me it's jonas is a f*cking stud!

by viewing the account_controller.rb, you will get an idea all the stuff that is exposed: index, login, signup, logout
so that means when you go to your site, http://localhost:3000/accounts/<operation>, just put the operation you want, and you will do one of the four

This is ezed signing off for part deuce!... Watch out for part tres for the rake migrations! nyahhhhhHH!
Jonas' Crazy Adventures in RoR - Part I - The Idea
After my pain, it is finally time to do some coding.
But I don't want to do any "hello rails" app, I want something that I would use. Well what do I need?
Iteration Management Tool!
I know... there are tons of those online, but hey I gotta do some shizzle. There is definately nothing wrong with my post-it notes style of showing my progress on a project, but it would be nice to do some graphs, some reporting, and some stuff to show me the status of my project on the world wide interweb.
Me and my buddy Neil had this idea before, but nothing really happened. I attempted in MonoRail, but it ended up like my other projects, I got lazy and moved on.
So for the idea, I whipped up a ghetto high-level database diagram of the tables. Nothing fancy... just what I need so far.

I really want this project to be a 2 week project, so I will pimp it up one day.
Stay tuned for Part deuce - the login!
peace! I'm uber pumped!
20070723
macports & ruby installation part II
I had to post another one... F*cking thing is a pain when it's the first time running it....
So this post is dedicated to anyone that has a mac and wants to pursue a macport way of installing RoR & MySQL
1) Download & install iTerm
2) Download & install XCode 2.4.1
3) Download & install macports
4) update /etc/profile or ~/.profile with the following PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
5) open iTerm and type: sudo port selfupdate
6) install ruby: sudo port install ruby rb-rubygems rb-termios
7) install mysql sudo port install mysql5 +server
8) create a symbolic link to mysql.sock: sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock
9) to autostart mysql: launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
10) configure mysql: sudo mysql_install_db5 --user=mysql
11) secure mysql: sudo -u mysql mysql_install_db5
12) start mysql: sudo -u mysql /opt/local/lib/mysql5/bin/mysqld_safe
13) update mysql root password: /opt/local/lib/mysql5/bin/mysqladmin -u root password 'your_password'
14) install ruby mysql adapter: sudo port install rb-mysql
15) Finally install rails and other stuff: sudo gem install rake rails capistrano mongrel mongrel_cluster deprec --include-dependencies
macports & ruby installation on my pimp macbook pro
I've decided to give RoR a shot again but this time with macports. For those people on the mac trying to develop RoR apps, macports is the way to go!
But here are some things that I did when im installing ruby on my mac:
1) Google "macports+rails"
2) mongrel doesnt work if you install it after rails. to avoid this pain, type "sudo gem install -y mongrel mongrel_cluster rails"
3) When running the webserver for the first time, make sure you update your /etc/profile configuration file to use the macport ruby not the default mac ruby found on /usr/bin. Sooo change this: PATH="/bin:/sbin:/usr/bin:/usr/sbin" to this PATH="/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin"
Now go .rb'ing like a mofo!
p.s. If you bought 
burn it and get
Rails changed dramatically on 1.2
20070709
Getting your CruiseControl.Net/.rb 's Project Status in C#
Ever wondered how to get a CruiseControl.Net/.rb project status?
Below is a spike I did to see if I can do it.
using System;
using System.Runtime.Remoting;
using MbUnit.Framework;
using Rhino.Mocks;
using ThoughtWorks.CruiseControl.CCTrayLib.Configuration;
using ThoughtWorks.CruiseControl.CCTrayLib.Monitoring;
using ThoughtWorks.CruiseControl.Remote;
namespace i.ma.gine.spike
{
[TestFixture]
public class CruiseControlMonitorSpike
{
[Test]
public void Create_ShouldCallCreate()
{
MockRepository mockery = new MockRepository();
ICruiseProjectManager mockManager = mockery.CreateMock<ICruiseProjectManager>();
ProjectStatus status = new ProjectStatus();
Expect.Call(mockManager.ProjectStatus).Return(status);
mockery.ReplayAll();
ProjectMonitor monitor = new ProjectMonitor(mockManager);
monitor.Poll();
Assert.AreSame(status, monitor.ProjectStatus);
mockery.VerifyAll();
}
[Test, Ignore("Just wanted to verify if I can actually connect to my CruiseControl.rb server")]
public void Create_ShouldCallCreateRunningRealCruiseControlServer()
{
ICruiseProjectManagerFactory cruiseProjectManagerFactory =
new CruiseProjectManagerFactory(new FakeCruiseManagerFactory(), new WebRetriever());
ProjectMonitor monitor =
new ProjectMonitor(
cruiseProjectManagerFactory.Create(
new Project("http://localhost:3333/XmlStatusReport.aspx", "imagine")));
monitor.Poll();
Console.Out.WriteLine(monitor.ProjectState);
Console.Out.WriteLine(monitor.LastBuildTime);
}
}
public class FakeCruiseManagerFactory : ICruiseManagerFactory
{
public ICruiseManager GetCruiseManager(string url)
{
return (ICruiseManager) RemotingServices.Connect(typeof (ICruiseManager), url);
}
}
}
With the following spike above, I was able to do this in code:
public static string Format(ICruiseControlProject project)
{
try
{
if (project.ProjectMonitor.ProjectState.ToString() == "Success")
return GetHTMLString(project.ProjectMonitor, "green");
return GetHTMLString(project.ProjectMonitor, "red");
}
catch
{
return string.Format("<font color=\"red\">{0}</font>", project.ProjectMonitor.ProjectState);
}
}
private static string GetHTMLString(IProjectMonitor monitor, string fontColor)
{
return
string.Format("<font color=\"{2}\">{0} - {1}</font>", monitor.ProjectState,
((ProjectMonitor) monitor).LastBuildTime, fontColor);
}
Note:
I imported the following .dll's from CCTray (1)ThoughtWorks.CruiseControl.CCTrayLib.dll (2)ThoughtWorks.CruiseControl.Remote.dll
20070706
Google Reader
Anyone know why Google Reader takes a long time to show new posts from blogger.com?
I had a post on July 2, and I just saw it on my google reader on July 6th.
Anyone has an answer to this?
Passive View + Rhino Mocks = P.I.M.P.
Okay, my previous post, I said that nMock2 was better - I changed my mind.
It was just that I didn't know how to use the damn tool. But having used Rhino Mocks for over 8+ months now It has become my favorite mocking tool...
To show you guys some nyahh, check this passive view mvp test using rhino:
[Test]
public void Load_ShouldLoadView()
{
MockRepository mockery = new MockRepository();
IPimpBlogView view = mockery.CreateMock<IPimpBlogView>();
IBlogPostTask task = mockery.CreateMock<IBlogPostTask>();
view.Load += null;
IEventRaiser raiser = LastCall.Constraints(Is.NotNull()).GetEventRaiser();
Expect.Call(task.GetBlogPosts()).Return(new List<IBlogPost>());
view.BlogPosts = new List<IBlogPost>();
LastCall.IgnoreArguments();
mockery.ReplayAll();
new PimpBlogPresenter(view, task);
raiser.Raise(null, null);
mockery.VerifyAll();
}
As you can see from the above test, that is f'in pimp... I used an event raiser to raise my "Load" method to pretend it did stuff to load all my blog posts...
Below is the code for the passive mvp for those who missed out on the "pink" of enterprise development last year:
public class PimpBlogPresenter
{
private readonly IBlogPostTask task;
public PimpBlogPresenter(IPimpBlogView view, IBlogPostTask task)
{
this.task = task;
view.Load += delegate { HookUpEventsFor(view); };
}
public PimpBlogPresenter(IPimpBlogView view) : this(view, new BlogPostTask())
{
}
private void HookUpEventsFor(IPimpBlogView view)
{
view.BlogPosts = task.GetBlogPosts();
}
}
The Form & View
public partial class PimpBlog : Page, IPimpBlogView
{
#region IPimpBlogView Members
public IEnumerable<IBlogPost> BlogPosts
{
set
{
blogPostRepeater.DataSource = value;
blogPostRepeater.DataBind();
}
}
#endregion
protected override void OnInit(EventArgs e)
{
new PimpBlogPresenter(this);
base.OnInit(e);
}
}
public interface IPimpBlogView
{
IEnumerable<IBlogPost> BlogPosts { set; }
event EventHandler Load;
}
In conclusion, Rhino Mocks is pimp. Thanks Ayende for making such an awesome weapon for dealing with the pain!
20070702
My DJ Setup
- Macbook Pro (1st Gen)
- Vestax - VCI 100 MIDI Controller
- M-Audio Fast Track Pro Audio Interface
- Vestax PMC 07 Mixer
- Technics 1200 M3D
- My Awesome Skills!
