Rails and Stuff at Abel killed Cain

Ruby on Rails and other Webdevelopment

PHP 5.3 lambda use case

March 6, 2010 General Comments

i just thought about iterating objects in php.

Since 5.3 supports lambda, i found this quite usefull:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Test {
        public $vals = array();

        function __construct(){
                $this->vals = range(1,10);
        }

        // the hooray goes here!
        function each($function){
                foreach($this->vals as $element){
                        $function($element);
                }
        }
}

$t = new Test;

//the real hooray-part:
$t->each( function( $e ) {
        echo "Hi, i am element $e\n";
});

Works! :)
[More]

Building Websites is fun!

Having IE6 Users sucks instead!

Get rid of them by pasting the following code into your document-head.

<!–[if IE 6]>
<script type=”text/javascript”>
alert(”No IE 6! Thanks!”);
document.write(’<style>*{position:relative}</style><table><input></table>’)
</script>
<![endif]–>

IE 6 will crash after asking the user not to use it!

Ruby on Rails provides a nice way to display error_messages; just by adding form.error_messages you get a nice overview of all your errors.

But i prefer to have it in different ways, so i 1) dont want the on_error_message-output to be a div element, 2) further i want to give each input field having bad content to be marked – by adding an error-class to that specific element for example.

Since i had to figure it out, here are the results for changing both.

1) different element instead of a div at on_error_message?
[More]

Rails logging methods are wonderful for development.

Indeed, they often suck when you want to inspect objects or cascaded objects. So here is a codesnipped that helps you inspect any kind of any object in rails, deeply and detailed.

as a new lib-file or, just as i do, in application_controller.rb, add the follogwing code:

[More]

Here is a small collection of Tips and Tricks for Ruby in association to Rails.

I will paste some irb-logs, displaying all results.
1. Format decimals or text quickly
[More]

This is more like a rather small hint, describing how to make tables sortable in rails.

Just like ryan bates shows in his rails casts, there is a similar way to sort tables, instead of lists.

Here the example-code how to make the tables sortable:
[More]

I wanted to have a rather simple pagination without next and previous buttons (yah, the post title told you, eh?).

However, did not find any option to deal with it. But Will_Paginate provides a nice way to overwrite the link renderer in order to have full customization.

So i created the following:
[More]

I had the following problem to solve using rails:

  1. Having 2 Subdomains, www and clients
  2. a client always has a path-prefix to use google analytics for each of this subdirs. so i had the following urls:
    www.domain.tld/foo.html  and clients.domain.tld/3kunsdf7w/foo.html
  3. I did not want to have a code on www.
  4. i did not want to alter all tempaltes with new paramters and differen routes

Solving this, it was ok for me to duplicate all routes with a client_  prefix using textmate, so i took onl 4 seconds.. but what next, how to tell rails to use the clients_xy_path when i call xy_path?

[More]

Today i was bored by svn. Filenames containing “special characters” can cause an annoying Subversion error message:

1
svn: Can't convert string from 'UTF-8' to native encoding:

From the subversion book:

Errors like this typically occur when the Subversion client has received a UTF-8 string from the repository, but not all of the characters in that string can be represented using the encoding of the current locale. For example, if your locale is en_US but a collaborator has committed a Japanese filename, you’re likely to see this error when you receive the file during an svn update.

To fix this error message you have to set your current locale appropriately:
[More]

Just a rather small hint for rails users.

Today i was getting angry about rails, since it told me that a specific method would not exist.. but i knew that i did exists, and both of us were wrong.

How come: i moved a method vom controller to helper, but forgott to remove it from helper_methods.

So Rails claims, that the gived method does not exists. Strange, but true, it complains when you call it in code or template,  silence when you just add it as helper_method.

So be warned, be smarter than i was ;)