Posted in Diari, English Linux, Programació, Rails, Ruby on 03/19/2010 03:53 pm by Ton
Hi there
These days I’m taking advantage of my daily train time watching railscasts episodes with my lenovo netbook. It’s really awesome all the things you can learn from these screencasts done by Ryan Bates about how to do things using rails.
Thanks a lot Ryan for sharing your knowledge with us.
M.
Posted in Diari, English Linux, Programació, Rails on 01/30/2010 07:00 pm by Ton
Hi
When a migration is created, rails add a column named id, which is defined as an integer, as table’s primary key column. Sometimes can happen that you don’t want to name your primary key column id using rails. The way you have to write your migration is this one (rails use integer type by default):
def self.up
create_table :airport, :primary_key => :airport_id do |t|
t.string :iso_code, :limit =>3, :null => false
t.string :name, :limit =>150, :null => false
t.integer :city_id, :null => false
end
end
If you have a “many to many” table probably you don’t want to have this id column in your table and you want to define two columns as primary key. This is the way you have to write a migration if you want to define this primary key:
def self.up
create_table :airports_cities, :primary_key => [:airport_id, city_id] do |t|
t.integer :distance, :null => false
end
end
In both examples, columns defined as primary key don’t have to be defined because rails do it for you. Using this, you won’t have an id column in your table and you’ll be able to use whatever you want as primary key (even strings).
Hope this helps (to my fish-like memory or to somebody else’s brain).
M.
Posted in Diari, English Linux, Programació, Rails on 01/12/2010 10:07 pm by Ton
Howto create the table to store sessions in Rails
rake db:sessions:create
Howto truncate all *.log files in log/ to zero bytes
rake log:clear
M.
Posted in Diari, English Linux, Programació on 12/20/2009 01:16 am by Ton
I always forget how to dump my blog’s mysql database. It’s :
mysqldump db_name -u username -p > filename
That's all
M.
Posted in Diari, English Linux, Programació, Ruby on 12/20/2009 12:44 am by Ton
I always forget how to add a source using rubygems. It’s (using ‘http://gems.github.com’ as example) :
gem sources -a http://gems.github.com
That’s all
M.
Posted in Diari, English Linux, Programació, Rails on 11/22/2009 01:13 am by Ton
Sometimes, a search has to be coded in an application and if you are using rails, probably you’ll use will_paginate. It is a good piece of software, easy to install and easy to use but, if it’s not used correctly, problems may appear.
I use it using a form_for rails’s tag and four search criteria in it. After coding it, I added will_paginate and after doing my first search, I paginated to the second page…it came empty. After googling a little, I noticed that I was sending info using POST method and will_paginate needs GET method to work properly, so the only thing needed was:
:html => { :method => :get}
and it worked perfectly, passing parameters to the next pagination.
Hope this helps, it’s something silly but sometimes silly things made people go into the dark side of coding
M.
Posted in Debian, Diari, English Linux, Rails, Ruby on 11/15/2009 02:05 pm by Ton
Hi dudes
I’m coding my web application and I need to use the simple_captcha gem, which uses rmagick to generate captchas. I’m trying to install it, I already have imagemagick installed in my debian sid, and I found the following problem
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for cc... yes
checking for Magick-config... no
Can't install RMagick 2.12.2. Can't find Magick-config in /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
Googling a little I found this page which explains what to do, which is ‘apt-get install libmagickcore-dev‘ as root or using sudo.
After this, a new error appears
Building native extensions. This could take a while...
ERROR: Error installing rmagick:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for cc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.3.5... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no
Can't install RMagick 2.12.2. Can't find MagickWand.h.
And a new action is taken ‘apt-get install libmagickwand-dev‘.
Problems solved and gem installed.
M.
Posted in Diari, English Linux, Programació, Rails, Ruby on 11/14/2009 01:05 pm by Ton
Hi there
I’m coding an application which has to upload files to the server. I have found an error when the uploaded file is saved in server directory. The message from system is
Status: 500 Internal Server Error
invalid byte sequence in US-ASCII
If you are in the same situation and want to solve it (it’s a rack 1.0.1 gem problem), you have three options:
- Wait for a new rack release.
- Apply the patch (I don’t know where it is).
- Apply manually the solution provided here.
Choose one
M.
Posted in Diari, English Linux, Rails on 04/02/2009 12:08 am by Ton
Hi there
Some of you would remember Railscast script, so I coded a new version using SQLite3.
The new version is this one and the empty database is that one.
Enjoy it
P.S. Remember to rename the empty database file from EmptyRailsCastDownloader.db to RailsCastDownloader.db.
Posted in Diari, English Linux, Rails on 03/29/2009 10:08 pm by Ton
Hi
As some of you know, I am coding using the Ruby On Rails framework right now. Apart of this, I am a huge fan of http://railscasts.com/ and I like to watch the screencasts published in it.
Some weeks ago and during four weeks, my internet connection took me back almost to the 56 Kb modem age (my download speed was 100 kbps) and I was not able to watch the published episodes. Years ago I coded a perl script named deb-downloader because I was in a similar situation and I had to upgrade my Debian sid so I decided to code a little ruby script to download all the episodes from wherever I was and watch them at home.
This is the script and it is used for downloading the episodes you don’t have (the episodes already downloaded are stored in a text file and to not be downloaded again). If you like this script, you are free to use it, modify it and distribute it (it is under the GPL license) and even send me suggestions about how to improve it or add new functionalities.
Btw, I have downloaded all the episodes and I’m waiting for the new one (it is usually published every Monday).