valibuk.net

A place for opinions and notes of a valibuk.

Removing constraints in migration

Tagged with: — ondrej at 7:44 pm on Wednesday, October 4, 2006

Ruby on RailsWith a migration you can create a table or insert data to a table, also there is a possibility to modify existing tables; from renaming tables to changing the type of a column. And what about constraint such as default value or not null?

Yeah, you can change them too, but I was only successful with adding them — removing them was not possible with standard Rails methods.
(There is more where this came from … )

Observing more fields with AJAX helper and Unicode

Tagged with: — ondrej at 11:01 pm on Monday, October 2, 2006

Ruby on RailsIn my post about using the observe_field helper for observing more fields I used the escape method (on the client side).

I have found out the code does not work correctly with Unicode characters :(
(There is more where this came from … )

Various Number of Conditions

Tagged with: — ondrej at 1:49 am on Monday, August 21, 2006

Ruby on RailsFiltering is basically about writing conditions. In most cases the number of conditions is fixed, e.g. an internal filter in an application. Then it is quite easy to prepare a value for the conditions parameter.

But what to do if a number of conditions may vary? It is not a good idea to pass an empty value, because an empty value is still a valid value. We have to somehow implicitly say that a condition with an empty value should not be taken into a filtering process at all.
(There is more where this came from … )

How to observe more fields with AJAX helper

Tagged with: — ondrej at 12:31 am on Tuesday, August 15, 2006

Ruby on RailsThe observe_field AJAX helper allows to observe one field; if there is a change, it calls the specified method on the server side. It is possible to attach one value for the call.

This is enough if we have one text box search for searching over multiple columns or for a full-text search.

For a more complicated filtering functionality with more fields there are two main problems with the observe_field helper:

  • how to specify more parameter values in the observe_field helper.
  • it is necessary to write a observe_field call for each field.

Added: Thanks to Ryan Bate and Benjamin, I found out there is a helper for the whole form: the observe_form helper. Basically my post is useless, except a few situations: if a form contains a lot of items and you would not like to send them all, or, and I am not 100% sure about this, if a form contains a file field (the file_field helper).

Let’s create a special observe_fields helper that will handle all this problems :)
(There is more where this came from … )

Form Helpers for Collection in One Form

Tagged with: — ondrej at 2:37 am on Sunday, August 6, 2006

Ruby on RailsA usage of form helpers for a single record is easy and straightforward. But how to use them for a collection of records in one form?

Do we need to edit a collection of records in one form? Well, there is always an option to let a user to edit records one by one, and we should use this option if the structure of a record is complex, e.g. a lot of items. If the structure is simple or we use a subset of a complex structure, we can allow a user to edit more records in one form. A good examples are labels of photos in a photo album, description and price for items in a web shop, etc.
(There is more where this came from … )

How To Use date_select for Birth Date Field

Tagged with: — ondrej at 11:08 pm on Tuesday, July 18, 2006

Ruby on Rails The date selection date_select widget by default contains years from five years before to five years after the current date.

This is not sufficient for a birth date field.
(There is more where this came from … )

Using Migrations for Generating Initial or Test Data II.

Tagged with: — ondrej at 2:58 pm on Sunday, July 16, 2006

Ruby on RailsLast week I wrote a post how to use migrations to enter initial (or test) data into one table. Now I will show how does it work for two tables with a join.

Firstly, we will create the second model Employee; the User model defined in the previous post is the first model.

The Employee model represents the domain specific part of person details such as first name, surname and date of birth; the User model represents the technically specific part such as login name and password.

(There is more where this came from … )

Using Migrations for Generating Initial or Test Data

Tagged with: — ondrej at 10:49 pm on Wednesday, July 5, 2006

Ruby on RailsThe migration functionality allows not only to create (and modify) tables and their columns but also to enter initial (or test) data.

Firstly we will create a simple example (only one table); in the second example we will create two joined tables and show how to generate data for them.

In general, for each table there will be two migrations — the first one creates a table and its columns, the second one inserts data.

(There is more where this came from … )

Ako lokalizovať aplikáciu v Ruby on Rails

Tagged with: — ondrej at 1:09 am on Thursday, June 29, 2006

Ruby on RailsPripravujem návod ako poslovenčiť aplikáciu napísanú v Ruby on Rails.

Možno sa návod objaví aj na slovenskej RoR stránke.

« Previous Page