I found this great guide on how to use forms in Ruby on Rails.
It is quite complete and it comes with a lot of examples on how to create HTML form entries using Ruby on Rails.
Thursday, April 9, 2009
Using forms in Ruby on Rails
Posted by
Daniel
@
4:00 AM
0
comments
Labels: rails, ror, ruby, ruby on rails, rubyonrails
Google App Engine with Java
Google now offers the possibility to use Java for its App Engine!
Posted by
Daniel
@
2:43 AM
0
comments
Thursday, April 2, 2009
Running tests in the command line on Ruby on Rails
I normally run the test suite for my Ruby on Rails projects using the Netbeans test interface.
Unfortunately this interface is only useful to run the whole suite. It does not offer (as it does for Java) the possibility to run a single test class or a single test from a test class.
When I need to this I just go to the command line and type:ruby test/functional/accounts_controller_test.rb
But what if I need to run one single test from this test class?
No problem, it is actually very easy. Just type:ruby test/functional/accounts_controller_test.rb --name test_should_create_account
That's it!
You can also find this article on definenull.com.
Posted by
Daniel
@
11:41 PM
0
comments
Labels: ror, ruby, ruby on rails, rubyonrails, test, testing
Tuesday, March 31, 2009
Ruby on Rails Order By Using Associated Model
It is very easy to use an 'order by' clause in a model in Ruby on Rails. Supposing you have a Category model it's as simple as doing this:
@categories = Category.find(:all, :order => 'title') But what if I need to order by the title of the subcategories after ordering by the categories title?
Using the category_id does not work, because it is almost sure that the categories will not be added in alphabetical order, so the command below does not work for me:
@subcategories = Subcategory.find(:all, :order => 'category_id,title')And neither would work the sentence below, because the resulting SQL query will fail:
@subcategories = Subcategory.find(:all, :order => 'category.title, title')This last command will fail because rails does not recognize the Category model inside the subcategories model. So all you have to do is tell Rails that you want to include another model in the query, and this is done using the :include option from the find method:
@categories = Category.find(:all,:include => :subcategories, :order => 'categories.title, subcategories .title')It is easy after you find out how! ;)
This article can also be found on definenull.com.
Posted by
Daniel
@
11:27 PM
1 comments
Labels: model, order by, rails, ror, ruby, ruby on rails, SQL
Friday, March 13, 2009
Sun Java One 2009 - topics released
Sun has released the topics for the Java One 2009 Conference, with four high-level areas: Mobility, Rich Media Applications and Interactive Content, Services and Core Content.
It will happen in San Francisco in June, 2nd-5th.
Posted by
Daniel
@
4:30 PM
0
comments
Labels: Conference, Java, javaOne, sun
Saturday, March 7, 2009
Cygwin personal setup
Some time ago I wrote a post on how to setup the looks of your Cygwin bash shell using rxvt. Well, I normally add a few more settings to my environment just to make it more useful.
I add the following lines to my ~/.bash_profile with some aliases to make it easier with directory surfing.
alias ls='ls --color=auto'
alias ll='ls -lsa'
alias l='ls -la'
It is also useful to set some preferences for vi, and this is done in the ~/.vimrc file:
set textwidth=70 background=dark
set is hls ic scs aw ruler ls=2
syntax on
I also like to create symbolic links at my home dir to allow me to have quick access to some of the original and most used folders in Windows, like:
ln -s /cygdrive/c/Documents\ and\ Settings/dambrosio/Desktop/ windesk
ln -s /cygdrive/c/Documents\ and\ Settings/dambrosio/Meus\ documentos/ mydocs
Some other useful symbolic links might be the ones pointing to your drives, because it is faster to type
cd ~/c than cd /cygdrive/c Quick and clean! ;)
Find this article also on definenull.com.
Posted by
Daniel
@
5:45 PM
0
comments
Tuesday, March 3, 2009
Change Default Date Format in Ruby on Rails
Just a quick and simple hint!
If you need to set the default formatting of dates throughout your whole application in Ruby on Rails, just add the following line to your "<your application>/config/environment.rb"
my_date_formats = { :default => '%d/%m/%Y' }
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_date_formats)
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(my_date_formats) Note 1: Rails uses this :default format when attempting to write dates do the database, so be sure that your DBMS is able to use this new format
Note 2: you will need to restart your server so the changes will be effective.Find this article also on Define Null.
Posted by
Daniel
@
1:57 AM
0
comments
Labels: date_formats, format, rails, ruby, rubyonrails