Blog

Tags:  •    •    •  

I've wrote these words on google. And I don't find the exact solution.

The problem:
What Should I write in the href? If I write # sign then browser go to the top of page. I wouldn't like to go to the top of page.

Here is the HTML:

<a href="#" id="example" >Click</a>

jQuery code:

<script>
$('#example').click(function() {
  alert('Hello');
  return false;
});
</script>

The return false; command is the key. When use this return value. The links lost their default behavior.

Tags:  •    •    •    •  

Today, I found a really good CMS. I'm looking for ruby 3 CMS for a while. I found this CMS solution that use my favorite NoSQL database system: MongoDB. I think multi site feature is rare in ror applications. Locomotive CMS do it.

Locomotive is an open source CMS for Rails 3. It's super flexible and integrates with Heroku and Amazon

Some features from technical Specs:

Tags:  •    •    •  

The problem

I want to write JavaScript files that use dynamic informations via Ruby on Rails. I think my solution also works with rails 2 and 3.
What can dynamic JavaScript do for you? You can write JavaScript on your ERB (embedded ruby) file beside HTML code. This is very simple, but not the best solution for a longer jQuery script.
For example:
Translation in JavaScript: translation with I18n.t() Rails method would be great in separated JavaScript file with ERB capability.

// some jquery code before alert
alert(<%= I18n.t(:forbidden_message) %>);
Tags:  •    •    •  

There are some importatnt step to install Nginx with passenger on a newly installed Ubuntu server.

1. step: Install RVM in multi-user mode
2. step: install dependencie for MRI ruby. There are a list in the end of rvm install message. Install these packages.
3. step: rvm install 1.9.2
4. step: After ruby installed successfully you need to install passenger with gem install passenger command.
5. step: You have got passenger gem, but haven't got nginx yet. Compile it from source: download, unpack, configure, make, make install.
6. step: nginx configuration

Tags:  •    •  

I post my normalization function. This function find all illegal characters (like: Ő, Ű, ú, í, etc. ) and replace it to latin1 chars. (like: O, U, u, i, etc.) This function works for me on hungarian words. Try it on your text and post your comment about it.

function normalize($string) {
    $string = strtr($string, array('ő' => 'o', 'ű' => 'u', 'Ő' => 'O', 'Ű' => 'U'));
    $a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖŐØÙÚÛÜŰÝÞßàáâãäåæçèéêëìíîïðñòóôõöőøùúûűüýýþÿŔŕ';
Tags:  •    •    •    •    •  

Here is an example, what show the way you can translate your mongoid models:
You can also customize error messages as you will see in the next example.

User model translation Example:
en.yml content:

en:
  mongoid:
    errors:
      models:
        user:
          attributes:
            email:
              blank: "You have to give me your e-mail address"
              not_found: "e-mail address not found in list of members"
              #...
    attributes:
      user:
        email: "Email address"
        name: "Your nickname"
        #...
Tags:  •    •    •  

I got the following error when i run a rake db:seed command on may RoR application:
invalid multibyte char (US-ASCII)

I found the soution and the error has gone away:
You should add a line to your file:

# encoding: utf-8

You can change the utf-8 to any other encoding that you use.
I added this line to my seeds.rb file and all UTF-8 code have been executed without errors.

Good luck!

Tags:  •    •  

Some useful git command with branches and remote repositories.

Remote operations

List remotes:

git remote -v

Add remote gitosis server:

git remote add <remote_name> git@myhostname.com:my_project_name.git
git push <remote_name> master

Where master is your branch name

Main git branch orperations

list branches:

git branch -v

-v is optional, you use it to get more verbose output

Create new branch:

git checkout -b <new_branch_name>
Tags:  •    •    •    •  

I've collected all open source CMS based on rails 3.x.

Rails CMS/Wiki/Forum

This is a very simple but feature rich CMS framework. It is good startpoint for a new rails project what will be wiki, Forum or CMS

Source: https://github.com/jlapier/Rails-CMS-Wiki-Forum

Casein CMS

This is a very minimal and lightweight CMS. Only users table created on rak db:migrate. It is a good start point for any content based application. This application scaffolding your rails app with a very beauty user interface.

Tags:  •    •  
function foo($year = date('Y')) {
  // this is invalid
}

So, how should do it?

define('THIS_YEAR', date('Y'));
function bar($year = THIS_YEAR) {
  // this is valid
}