Wpisywanie danych do bazy z pola select

Mam taki formularz:

[code]…

<%= f.label :type %>
<%= f.select :type, Status_type.all.collect {|p, q| [q, p] } %>

...[/code] Taki kawałek modelu: [code]... def self.all {0 => "Zgłoszone", 1 => "Zaakceptowane"} end ...[/code] Fukcje do tworzenia. Tak nakombinowane, gdyż dane wychodzące z selecta są stringiem, ja potrzebuję integer. [code]def create @par = params[:status] @par['type'] = @par['type'].to_i @status = Status.new(@par)
respond_to do |format|
  if @status.save
    flash[:notice] = params[:status].inspect
    format.html { redirect_to(@status) }
    format.xml  { render :xml => @status, :status => :created, :location => @status }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @status.errors, :status => :unprocessable_entity }
  end
end

end[/code]
I taką tabelę:

[code]…
create_table :statuses do |t|
t.integer :type
t.text :description, :null => true
t.datetime :date, :null => true

  t.timestamps
end

…[/code]
Po wypełnieniu formularza niby wszystko ładnie dodaje. Przekazane dane pokazuje tak:

{"date(1i)"=>"2009", "date(2i)"=>"6", "date(3i)"=>"24", "notification_id"=>"1", "date(4i)"=>"08", "date(5i)"=>"19", "type"=>0, "description"=>"Banshee"}

ale mimo tego do bazy nie wpisywana jest wartość “type” z pola select (inne są) - w tabeli jest null.
Dlaczego tak się dzieje?

Pozdrawiam,
sebcioz

Nie mozesz uzywac pola “type” no chyba ze do STI. Slowo “type” jest zarezerwowane przez Railsy.

Tego się obawiałem :wink:
W każdym razie dzięki.

Dobrym zamiennikiem “type” jest “kind”.