Category: Diari

Rails form_tag

Hi

I know there are a lot of posts about the rails “dangerous” form_tag helper method, but why not another one.

Before saying anything about it, I want to write down the differences between form_tag and form_for (which was the choosen one previously). form_for is provided for updating data models and form_tag is provided for doing the other form operations (search something, change language in a page, etc).

Ok, after this, let’s go to the battle. This was my code

< % form_tag :controller => 'pages', :action => 'index' , :method => 'get' do %>
Tags : < %= text_field_tag :tags, '', :size => 40 %>
< %= submit_tag 'Search' %>
< % end %>

and I didn’t got the html code what I wanted to obtain, after googling for a while, I found this post which got me to the right way to see the light. The reason of this problem was that I was not using the right syntax for form_tag, which is

form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)

so my code became

< % form_tag({:controller => 'pages', :action => 'index'} , {:method => 'get'}) do %>
Tags : < %= text_field_tag :tags, '', :size => 40 %>
< %= submit_tag 'Search' %>
< % end %>

and I was happy again :-D

Hope this silly problem helps not to waste your time (I did it for you ;-) )

M.

Routes in rails

Two days ago, I was solving bugs in my new professional website (not available yet at http://www.miqueloliete.com) when I stared at the screen and noticed how ugly my url was (something/home/home).

In that moment I remembered that I had read something in Agile Development with rails about how to use routes.rb, so I decided to give it a go.

I add to this files these sentences

map.connect 'home/', :controller => 'home', :action => 'home'
map.connect 'about_me/', :controller => 'home', :action => 'about_me'
map.connect 'cv/', :controller => 'home', :action => 'cv'
map.connect 'projects/', :controller => 'home', :action => 'projects'

and ‘home/home’ became ‘home’, ‘home/cv’ became ‘cv’, etc

M.

Ruby Version Manager (RVM)

Hi

I was fighting with my installed different ruby versions and I had heard about rvm, but I didn’t have use it. I decided to do today and I installed it using

gem install rvm

After it I tried installing two different ruby versions but I always obtained the same ruby version (the aptitude installed one). After that and googling a little I noticed (after typing type rvm | head -n1 and doesn’t read “rvm is a function”) that I had forgotten something in my .bashrc file, which was:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

And after that and opened a different konsole I could change my ruby version using ‘rvm use ruby-version’

Cool!!!!!

M.

Kubuntu Lucid Lynx upgrade

Hi people

I have an “old” Fujitsu Siemens amilo laptop and I upgraded my Kubuntu to Lucid Lynx (10.04) to bring the laptop with me in holiday. The thing is that after the process (which was done OK), my laptop got frozen showing a black screen (video card problem, an Intel 82852/855GM).

After googling a lot I found this post which gave me the magic to make my laptop usable again, which is (I don’t know what it does YET.

echo options i915 modeset=1 | sudo tee /etc/modprobe.d/i915-kms.conf
sudo update-initramfs -u

Now my laptop is working fine (I removed all the nvidia packages because somebody said that those packages could do this effect).

Hope this helps to somebody.

M.

Git & Debian Etch

Hi

If you try to initialize a public git repository with an existing one in Debian Etch, you will obtain this message:

$ mkdir public-repo
$ cd public-repo/
$ git --bare init --shared
git: 'init' is not a git-command

The most commonly used git commands are:
add Add files to the index file
apply Apply patch on a git index file and a work tree
archive Creates a archive of the files in the named tree
bisect Find the change that introduced a bug
branch List, create, or delete branches.
checkout Checkout and switch to a branch
cherry-pick Apply the change introduced by an existing commit
clone Clones a repository
commit Record your changes
diff Show changes between commits, commit and working tree, etc
fetch Download objects and a head from another repository
grep Print lines matching a pattern
init-db Creates an empty git repository
log Show commit logs
merge Grand Unified Merge Driver
mv Move or rename a file, directory or symlink
prune Prunes all unreachable objects from the object database
pull Pull and merge from another repository or a local branch
push Update remote refs along with associated objects
rebase Rebase local commits to a new head
reset Reset current HEAD to the specified state
revert Revert an existing commit
rm Remove files from the working tree and from the index
show Show one commit with difference it introduces
show-branch Show branches and their commits
status Show working tree status
tag Create a tag object signed with GPG
verify-tag Check the GPG signature of tag
(use 'git help -a' to get a list of all installed git commands)

This is because the git version which is in Debian Etch is too old (current: v1.7.2.1, etc: v1.4.4.4) and this command is not included in it. The first thing you have to do, if you can, is uninstall this git version and install a newer one, but if you can’t do it, this is the workaround I did.

  1. Create an empty git repo in a machine with a newer git version using git --bare init --shared.
  2. Copy the content of this repo in your public repo.
  3. Copy your local project in the machine with the too old git version
  4. Execute the command git --bare fetch $PATH_TO_LOCAL_COPY master:master
  5. Voila

The next step will be git clone user@server:/path/to/public/repo/.

Hope this helps

M.

Netbeans and Git

When I started to use Netbeans for coding with Ruby and Rails, I tried to use svn with it and it was a mess because I don’t know why yet I was not able to do commits from Netbeans (I used to do them from command line).

Since I use git instead of svn as my revision control system I have to say that I’m working with it and Netbeans since the first day I started using Git.

Cool

M.

Git I

After one of my Rails group meetings and all the great things somebody explained me about this distributed revision control system, I decided to give it a go and I started reading the Scott Chacon’s tutorial in order to start using git in one of my personal projects (my own website still in development).

I have to say that, after the three or four things I have done until now with it, git has surprised me a lot. It’s really fast, clear and it covers all my needs in control system tasks. I am svn user at work and I have to say that git is extremely faster than svn in merges (almost in the two I have done using git instead of svn).

Now I have only a repository in my computer but I supose I will have a central repository in the shared server I have with some friends of mine just in case my computer decides to pass away.

This post is named Git I (I don’t know if I will write more Git related posts) just in case :-)

M.

Un video per guardar ;-)

Hola

Aquest és un video que vaig veure fa molt temps i que va bé tenir-lo localitzat.



Salut

M.

Al least, yahoo.es pop is alive

Hi there

I’ve been a long time without fetching emails from my list yahoo.es’s email address. Finally I could do it three days ago and a lot of emails came to my inbox.

I’m reading right now all my list emails (Badopi, Claws-mail, BarcelonaOnRails, etc) and I’m discovering a lot of things I missed last two months.

I’m back

M.

Rest in peace

Yesterday, a great singer, songwriter and person passed away…rest in peace Ronnie James Dio.

His wife left this message in this great artist’s website.

Message from Wendy Dio

Today my heart is broken, Ronnie passed away at 7:45am 16th May. Many, many friends and family were able to say their private good-byes before he peacefully passed away. Ronnie knew how much he was loved by all. We so appreciate the love and support that you have all given us. Please give us a few days of privacy to deal with this terrible loss. Please know he loved you all and his music will live on forever.

- Wendy Dio

And I say, see you there Ronnie…whenever it is.

M.