[ruby-it] Inserimento record nel database via form

Roberto Casadei robyonrails a katamail.com
Ven 6 Apr 2007 00:03:49 CEST


Database: mysql. Tabella: learned_things. Modello: LearnedThing.

Qui la form nella vista:
<%= form_tag :action=>"add", :method=>"post" %>
    <%= hidden_field "learnedthing", "learned_on",
:value=>Date.new.strftime("YmdHis") %>
    Testo <%= text_field "learnedthing", "content", "maxlength"=>250,
"size"=>60  %>
    <br /><%= submit_tag "Aggiungi" %>
<%= end_form_tag %>

Qui l'azione "add"
  def add
    if request.post?
      elem = LearnedThing.new(params[:learnedthing])
      flash[:error] = "Impossibile aggiungere l' elemento nel database"
unless elem.save
    else
      flash[:error] = "Impossibile elaborare la richiesta"
    end
    redirect_to :action=>"index"
  end


Mi ritorna: Impossibile aggiungere elemento l' nel database

-- 
Posted via http://www.ruby-forum.com/.


Maggiori informazioni sulla lista Ml