About concept47

Ruby/Rails/Jquery/MySql/PostgresSQL hacker. Wannapreneur. Love to build beautiful things.

How to get a hasMany dropdown/select tag in cakephp

Getting a dropdown of items a model hasMany of, should be very easy to do, but I always forget and it takes me far longer to find it than it should.

For this brief example, we’re assuming that we have an Uploads model and a FileCategory model.
Uploads belongs to FileCategory and File Category has many Uploads … get it?

class Upload extends AppModel {
   var $belongsTo = array('Client', 'FileCategory');
}
 
class FileCategory extends AppModel {
   var $hasMany = array('Upload');
}

All you need to do to is get the items for the dropdown with a find(‘list’) command and then Continue reading

Cakephp gotcha: Don’t name controller the same as folder in webroot

This one had me going for a bit, but if you name a controller the same as a file that is in the “webroot” folder, and try to navigate to it, cake will just show you a listing of all the files in the same named directory.

As an example, the “files” folder comes with the cakephp installation right?

Not knowing that, I tried to build a files controller and navigate to it.

but it takes me instead to Continue reading

json_encode error “missing ] after element list” with jquery json plugin

If you’re using the excellent jquery json plugin you might run into problems trying to parse json returned from the php function json_encode.

Specifically, when you try to parse the returned json using $.evalJSON you get the javascript error

missing ] after element list

I also had this same problem with the cakephp json component (which I decided to use instead since it would be more portable across php versions than the php5.2+ only json_encode).

The simple fix is this.
Add slashes to your output and surround it with double quotes like this …

$status = json_encode($status);
echo '"'.addslashes($status).'"';

I figured this one out, by examining rails json output that worked just fine with the jquery json plugin.

Using the zebra widget with jquery Tablesorter (styling alternate table rows)

I ran into this problem trying to figure out how to make sure that styling alternate rows in a table did not become messed up when tablesorter actually sorted the table.

In googling around I figured out that you had to use the zebra widget call in your initial tablesorter contructor. But no one said exactly how to get the zebra widget to apply the alternate row styling.

The simple answer is Continue reading

Why Google is the best in the business … and you could be too

I was trying to find out how the NY Giants did last night, so I could incorporate it into a nice little jibe I was going to hurl at a friend of mine, so I went in and typed “NY Giants” … into the search box, to start the ever familiar process of clicking on links and backing up until I found what I wanted.

Guess what came up?

Its like they read my mind! 😀

Funny, but it illustrates *exactly* why Google is kicking everybody’s ass at search. 

They write software that anticipates the needs of its users. 

You should be asking yourself if your software, business, employees or personal service does the same.

New version (2.0.4) of Phusion passenger/mod rails out

New release announced

Global queuing

We recently announced that we’ve developed a feature called global queuing. This feature was requested by 37signals. When global queuing is on, Phusion Passenger will load balance all incoming requests into the first available backend process. This is especially useful if you have long-running requests, e.g. requests that perform heavy calculations and can take several seconds to finish. 

Fixed compatibility with the latest Rake version and RubyGems version

When compiling Phusion Passenger using the latest Rake, compilation commands are not shown while various warnings are being shown. This has been fixed. Various RubyGems deprecation warnings have also been fixed.

Running background programs from within the Rails app won’t freeze the request

In previous versions of Phusion Passenger, if one executes

system(“sleep 10 &”)

from within the Rails app, then Phusion Passenger won’t finish the request until 10 seconds have gone by. In other words, Phusion Passenger would wait until the background program has finished. This issue is caused by file descriptor leaks, and has been fixed.

Fixed Mac OS X crash

A Mac OS X related crash has been fixed.

Various bug fixes

The title says it all. If you experienced any kind of problems with previous releases, please try this release as the bug may have been fixed.

How to import/export your Netbeans settings to a new version

I’m a big fan of the Netbeans IDE, because I love the support it provides for Ruby on Rails.

It means that I upgrade my IDE to the latest release (Milestones, Betas etc)  as soon as it comes out, but it also means that with every upgrade, I have to physically go and set every … single … option … again.

Sounds painful doesn’t it?
It is.

Luckily , I found a blog post that describes how to solve this problem and import your netbeans settings from version to version.

This is something that needs to be fixed in Netbeans … that and including a word wrap option … and cakephp support … oops … getting carried away there 😀

How to search with Google Chrome using the omni bar

I’m writing this post because there doesn’t seem to be much instruction about how to search effectively from the url bar or omni-bar as the google folks call it.

The way its supposed to work is that if you type in a keyword for the search engine then the search query and hit enter, the search will execute using the search engine you specified.

so if you type 

“amazon.com Art of Rails” 
(note the space between amazon.com and the query)

into the omni bar then hit enter, your search will execute on Amazon.com.

To know that you’re doing it right, after typing in the keyword (amazon.com) and space, the url should look something like this

Continue reading

Google releases new Browser … its sexy

Yesterday I awoke to news about Google Chrome … EVERYWHERE.

And being the non-conformist I like to think I am (like everybody else in the universe), I wasn’t even going to give it a look until I stumbled onto this brilliant marketing tool that they had put together. Its a 40 page comic book walking you through the thought process behind why Google Chrome came about, and how it is different from everything on the market already.

What makes this puppy different?
The main philosophical difference between this browser and others is that fact that, instead of running the browser in one memory space, each tab in the browser has its own process.

Continue reading

andlinux = Fail (rant)

Its admirable what they’re trying to do, but I installed the software and couldn’t get it to run. (Strange “could not connect” errors)

After screwing around with their rather unhelpful help thread and losing 2 hours of my life I gave up and uninstalled it. Don’t waste your time like I did, until they at least figure out how to make the darned thing work right out the box.

Thats probably why I hadn’t heard about them until a few days ago, and then, entirely by accident.

Use BREAD not CRUD

From Paul m. Jones

“I don’t recall where I first heard the term BREAD; it stands for “browse, read, edit, add, delete”. That covers more of what common web apps do, including the record listings. It even sounds nicer: “crud” is something icky, but “bread” is warm and fulfilling. That’s why I tend to use the term BREAD instead of CRUD …”

I like BREAD.
🙂

gem install error – ‘cl’ is not recognized as an internal or external command

UPDATE: See my new blog post on the issue

If you’re here,  you are probably getting an error like this during a gem install on a windows box.

cl -c  -nologo -O1 -MD -Zi -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRICT -DHAV
E_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFIX –
O1 -MD -Zi -DNDEBUG    -DVERSION=\”6.4\”  -DXS_VERSION=\”6.4\”  -IC:\Perl\lib\CO
RE  BitVector.c
‘cl’ is not recognized as an internal or external command,
operable program or batch file.
NMAKE :  U1077:
Stop.

The fix is easy if you have visual studio or the .NET SDK installed.

If you don’t then either go download Visual Studio Express or the .NET SDK (anyone out of 1.1, 2.0 or 3.5 should do)

Now, do a search on your local machine for ‘cl.exe’ Continue reading

Zed Shaw is a fan of Phusion Passenger (modrails)

Its old but I stumbled onto this just today. Zed Shaw (the creator of that ol’ faithful Ruby server mongrel) is a fan of the Apache Passenger (modrails) guys

I also met the Phusion Passenger guys and holy fucking crap are they on to something. If anyone is going to actually take on Mongrel in the hosting area it’s Passenger. The developers are super cool nice guys (unlike me) and even DHH likes their stuff. He really never liked anything I built, so hopefully those guys get more support. About the only thing keeping them from taking over is that they use forking so a few libraries that keep resources open will have serious problems. They’ll probably have to think up some kind of thing for that soon, but I think most Rails deployments could get pretty far with Passenger. Continue reading

New mod_rails/passenger memory tools and cool tutorial

I’ve been mucking around with passenger quite a bit these days. I’ve got two staging servers running it for two different projects and another running a production version of one of those projects.

In digging through the documentation I discovered two new command line tools that come included with the 2.0 version of Passenger.

From the documentation
passenger-status

One can inspect Phusion Passenger’s internal status with the tool passenger-status. This tool must typically be run as root. For example:

Continue reading