代码之家  ›  专栏  ›  技术社区  ›  Brian

textarea的RoR设置值

  •  17
  • Brian  · 技术社区  · 14 年前

    有没有办法指定 text_area 方法,该方法将放置在生成的 textarea 标签?

    这是我正在使用的代码的一个例子。

    <% remote_form_for ... do |f| %>
          <%= f.text_area :message %>
          <%= f.submit 'Update' %>
    <% end %>
    
    3 回复  |  直到 10 年前
        1
  •  25
  •   Jed Schneider    14 年前
    <% remote_form_for ... do |f| %>
          <%= f.text_area :message, :value => "my default value" %>
          <%= f.submit 'Update' %>
    <% end %>
    
        2
  •  5
  •   adhundia    10 年前

    <%= f.text_area :message, :placeholder => "my default value" %>
    
        3
  •  4
  •   Lee Jarvis    14 年前

    text_area 方法采用第二个参数来指定返回textarea主体的方法。

      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>