Forum: Ruby on Rails 3 questions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
70dc5b6a5bf97779ee34d2865539f50b?d=identicon&s=25 Martin Luy (luma)
on 2007-04-13 19:16
(Received via mailing list)
1)
validates_format_of   :name, :with => /\A(\w(?:[\/' \-\.])?)*\Z/i

What does the 'i' do at the end of the regular expression?


2)
Should I do validation for attributes that are not from a form?


3)
  def self.up
    create_table :customers do |t|
      t.column :number, :integer, :limit => 4
    end
  end

As far as I know, Mysql 5.0.27 uses Int for number here. Will also a
small number need 4 bytes in the database?
F5d61a3c93217e393cfdf7bf5c7ac628?d=identicon&s=25 Michael D. Ivey (Guest)
on 2007-04-13 19:42
(Received via mailing list)
> validates_format_of   :name, :with => /\A(\w(?:[\/' \-\.])?)*\Z/i
>
> What does the 'i' do at the end of the regular expression?

/i makes a regex case-insensitive.  See
http://www.ruby-doc.org/core/classes/Regexp.html#M001219
for other Regexp options
E811b5337bcad19d52c8fed3a0ea0075?d=identicon&s=25 John Miller (jfmiller28)
on 2007-04-13 20:04
Hi Martin,

Martin Luy wrote:
> 1)
> validates_format_of   :name, :with => /\A(\w(?:[\/' \-\.])?)*\Z/i
>
> What does the 'i' do at the end of the regular expression?

It makes the match case insensitive

>
>
> 2)
> Should I do validation for attributes that are not from a form?
>

Yes.  If you expect a field to conform to condition that is not inherent
in it's column type you should validate the data.  It will catch bugs
and keep you data more coherent.

>
> 3)
>   def self.up
>     create_table :customers do |t|
>       t.column :number, :integer, :limit => 4
>     end
>   end
>
> As far as I know, Mysql 5.0.27 uses Int for number here. Will also a
> small number need 4 bytes in the database?

Yes.  It really isn't a big deal.  There are ways around this, but
before you go hacking into the code ask yourself if this isn't premature
optimization.  unless you are storing ~10^6 rows your space savings will
not be appreciable.

J. F. Miller
3c458017e52f646945b899aa5d380a0f?d=identicon&s=25 Matthew Isleb (misleb)
on 2007-04-13 20:06
Martin Luy wrote:
> 1)
> validates_format_of   :name, :with => /\A(\w(?:[\/' \-\.])?)*\Z/i
>
> What does the 'i' do at the end of the regular expression?

Case-insensitive

> 2)
> Should I do validation for attributes that are not from a form?

Depends on how much you trust yourself. Where is the data coming from?


>
>
> 3)
>   def self.up
>     create_table :customers do |t|
>       t.column :number, :integer, :limit => 4
>     end
>   end
>
> As far as I know, Mysql 5.0.27 uses Int for number here. Will also a
> small number need 4 bytes in the database?

As far as I can tell, it doesn't matter what "limit" you give to an int
in MySQL , it always uses 4 bytes. I don't believe you have access to
the various int types (bigint, smallint, mediumint) through migrations.

-matthew
This topic is locked and can not be replied to.