As a Rails newbie I spend a lot of time flipping through the books I have, scouring Google, and reading the Rails documentation. So far I think the biggest weakness of Rails has been the docs - they’re a bit obtuse, lack comprehensive examples, and as of Rails 1.2.2 the online docs are out of date.
This is not intended to be an attack - Rails is still so relatively new and progressing so quickly that it’s inevitable the docs lag behind. After all, who wants to write docs when they can write code? And writing good docs is extremely hard (every programmer I know thinks they can write docs, few bother to try, fewer still succeed).
Fortunately there’s a concerted effort to improve the Rails docs. You can check out their progress at http://fearoffish.clientsection.com, Login: guest, Password: guest.
Good stuff!
chris on February 27th 2007 in /dev/rails
…it were this distro: Windows for Warships nears frontline service.
One question: does it still have minesweeper?
chris on February 26th 2007 in /dev/random
The syntax for creating forms with Javascript onSubmit() events using the new form_for tag is not readily apparent so:
RUBY:
-
<% form_for :user_group, :url => { :controller => :user_group, :action => :new }, :html => { :onsubmit => "return validate_user_fields( this );" } do |form| %>
(Yes, the use of :controller => :user_group is redundant since Rails can infer the controller from the context of the current controller but I like the readability of it. It helps solves the "'What the heck is this really supposed to do?' six months from now" question quite handily.)
chris on February 26th 2007 in /dev/rails
The fastest sorting algorithm ever: Intelligent Design Sort.
chris on February 25th 2007 in /dev/random
This is a first test post of the blogging capabilities from within TextMate. If this works as well as it is supposed to, I'll be very impressed.
Update: I am very impressed indeed!
chris on February 22nd 2007 in /dev/random
Tonight I got this error when executing a .find( :all ) on a seemingly innocuous database table:
compile error
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/base.rb:1359: parse error, unexpected tINTEGER Object::3
After a bit of bashing about I figured out that this was because I'd named one of the fields in the table as type.
The moral of the story: don't name table fields type or Rails will puke on you. So, are there other not-recommended field names?
chris on February 22nd 2007 in /dev/rails
After much scouring of the web and various Rails books I finally figured out how to generate a form select pop-up that self-submits to the page to update content (no Ajax in this... yet).
This goes into the view:
RUBY:
-
<% form_for :user_group, :url => { :controller => :user_group,
-
:action => :select } do |form| %>
-
<%= form.select :id, UserGroup.find( :all, :order => 'name ASC' ).collect { |group| [ group.humanize_name( group.name ), group.id ] }, {}, :onchange => "selectGroup( this );" %>
-
<% end %>
This is the javascript function that gets called when the form select is changed. Goes into the HTML page (or better, an included javascript file):
JAVASCRIPT:
-
function selectGroup( $pSelect )
-
{ location.href = '?user_group_id=' + $pSelect.value; }
This goes into the controller. In my case the function called is "create", yours will probably differ:
RUBY:
-
def create
-
# Check that the group value was passed in. If no value, select a default
-
params[:user_group_id] != nil ? user_group_id = params[: user_group_id] : user_group_id = 1
-
-
# instantiate a group and store the selected id in it so that select item can be selected when next the page is generated
-
@user_group = UserGroup.new
-
@user_group.id = user_group_id
-
...
-
# rest of the logic here
-
...
-
end
chris on February 21st 2007 in /dev/rails
It's been almost a year since the last release but better late than never. DropBock 0.5.1 has been released: Download.
This is a maintenance and bug-fix release with emphasis on getting DropBocks to play nice with PHP 5. If you're using DropBocks I highly recommend updating to this version.
Change log:
- fixed missing <?php in index.php
- upload_max_size and post_max_size now quoted in source to prevent 'unitialized constant' warnings
- $REMOTE_ADDR now $_SERVER['REMOTE_ADDR']
- now warns if the maximum size is set greater than PHP's post_max_size value
- better unit conversion when displaying large files in the admin interface
- admin interface shows how many more files the dropbox can accept before it is full
chris on February 20th 2007 in /dev/random
I tend to use the noun "data" often in my database tables, often when a separate table stores the associated data to another object (ie: project.user and project.user_data). I also tend to think of the word "data" as being both the singular and plural of the same thing which tends to result in my typing
chris$ script/generate model user_data
when I want to create a new Rails model. However Rails then expects my database table to be called project.user_datas and thus my model fails.
The correct singular for "data" is "datum" and hence:
chris$ script/generate model user_datum
chris on February 17th 2007 in /dev/rails
The juggernaut continues - version 0.2 of this module adds much better support for borders on graph elements, the ability to display a graph legegend and support for images as background elements for the graph.
Read the docs here or view the source code here.
chris on February 16th 2007 in /dev/rails