Я пытаюсь создать предварительный просмотр для своей текстовой области:
Я пробовал это:
Мой контроллер:
def preview
post = Post.new(params[:post])
render :text => post.body_html
end
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
И моя форма:
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :titel %><br />
<%= f.text_field :titel %>
</div>
<div class="field">
<%= f.label :body_html %><br />
<%= f.text_area :body_html %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Как мне сделать предварительный просмотр в моей форме текстовой области body_html?Я хочу иметь предварительный просмотр, когда что-то вводится в body_html text_area, оно мгновенно просматривается.