views:

32

answers:

2

Hi,

I cant seem to figure out how to put text in between the generate textarea tags.

Is there a way to specify a value in the RoR textarea tag that will be placed between the generated textarea tags?

This is an example of the code I am using.

<% remote_form_for ... do |f| %>
      <%= f.text_area :message, %>
      <%= f.submit 'Update' %>
<% end %>
+2  A: 

The FormHelper text_area method takes a second argument to specify the method which returns the body of a textarea.

From the documentation linked above:

  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>
injekt
So I would write a method in a controller that returns the body of the textarea?
Brian
@Brian No, your model should handle that. For example using the method :text, would invoke the method `text` on your message model, assuming @message contains an instance of your model.As you can see from the example, `text_area(:post, :body)` invokes the method `@post.body`
injekt
Well, I added a method to my model like sodef default_text "testing"endThen <%= :message, :default_text %>But get the following error"undefined method `merge' for :default_text:Symbol"
Brian
A: 
<% remote_form_for ... do |f| %>
      <%= f.text_area :message, :value => "my default value" %>
      <%= f.submit 'Update' %>
<% end %>
Jed Schneider
That seems to work fine. Thank you
Brian