Il metodo text_area FormHelper prende un secondo argomento per specificare il metodo che restituisce il corpo di una textarea.
Dalla documentazione linkato sopra:
text_area(:post, :body, :cols => 20, :rows => 40)
# => <textarea cols="20" rows="40" id="post_body" name="post[body]">
# #{@post.body}
# </textarea>
text_area(:comment, :text, :size => "20x30")
# => <textarea cols="20" rows="30" id="comment_text" name="comment[text]">
# #{@comment.text}
# </textarea>
text_area(:application, :notes, :cols => 40, :rows => 15, :class => 'app_input')
# => <textarea cols="40" rows="15" id="application_notes" name="application[notes]" class="app_input">
# #{@application.notes}
# </textarea>
text_area(:entry, :body, :size => "20x20", :disabled => 'disabled')
# => <textarea cols="20" rows="20" id="entry_body" name="entry[body]" disabled="disabled">
# #{@entry.body}
# </textarea>
fonte
2010-08-26 22:39:07
Quindi vorrei scrivere un metodo in un controller che restituisce il corpo della textarea? – Brian
@Brian No, il tuo modello dovrebbe gestirlo. Ad esempio, utilizzando il metodo: text, invocherebbe il metodo 'text' sul modello del messaggio, assumendo @message contiene un'istanza del modello. Come si può vedere dall'esempio, 'text_area (: posta,: il corpo)' invoca il metodo '@ post.body' –
Beh, ho aggiunto un metodo per il mio modello in questo modo def default_text "testing" fine Poi <% =: messaggio,: default_text%> Ma il seguente errore "indefinito metodo' merge' per: default_text: Symbol" – Brian