Class: State

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/state.rb

Overview

States are "states, territories and provinces" of a country. This table is seeded from

 the db/seeds.rb file.  The seed data is supplied by db/seed/international_states/*.yml files.

If you need to seed a state other than a state in the United states You should watch the following video:

http://www.ror-e.com/info/videos/2

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Arel) all_with_country_id(c_id)

filter all the states for a form for a given country_id

Parameters:

  • country_id (Integer)

Returns:

  • (Arel)


49
50
51
# File 'app/models/state.rb', line 49

def self.all_with_country_id(c_id)
  where(["country_id = ?", c_id])
end

+ (Array[Array]) form_selector

method to get all the states for a form

['NY New York', 32], ['CA California', 3

... ]

Parameters:

  • (none)

Returns:

  • (Array[Array])


41
42
43
# File 'app/models/state.rb', line 41

def self.form_selector
  find(:all, :order => 'country_id ASC, abbreviation ASC').collect { |state| [state.abbrev_and_name, state.id] }
end

Instance Method Details

- (String) abbrev_and_name

the abbreviation and name of the state separated by '-'

Parameters:

  • (none)

Returns:

  • (String)


32
33
34
# File 'app/models/state.rb', line 32

def abbrev_and_name
  abbreviation_name
end

- (String) abbreviation_name(append_name = "")

the abbreviation and name of the state separated by '-' and optionally appended by characters

Parameters:

  • (none)

Returns:

  • (String)


24
25
26
# File 'app/models/state.rb', line 24

def abbreviation_name(append_name = "")
  ([abbreviation, name].join(" - ") + " #{append_name}").strip
end