1

有这些文件

  • 意见/sign_up/new.html.erb
  • 意见/sign_up/content.text.erb

我想content.text.erb默认显示这个 text_area 中的内容。
我怎样才能?

意见/sign_up/new.html.erb

<%= text_area :page, :content, :readonly => 'true', :size => '250x10' %>

意见/sign_up/content.text.erb

Hello

Are you seeing this?


This should be at Line 6.
4

2 回答 2

2

根据文档,您需要设置@page.content(因为您的前两个参数:page:content)。如果这是不可能的,我会退回到标准的“硬编码”文本区域,比如<textarea><%= render file: "sign_up/content" -%></textarea>

于 2013-01-29T10:38:46.270 回答
1

While I haven't tested it your answer should look about this:

<%= text_area :page, :content, :readonly => 'true', :size => '250x10', :value => render_to_string("/sign_up/content") %>

You may need to apply html_safe on the returned string from render_to_string

UPDATE:

After trying myself I got an error so I came up with a workaround:

1 - set @val in your controller the following way:

@val = render_to_string(:file => "/sign_up/content.html.erb", :layout => false)

2 - Then in your view:

<%= text_area :page, :content, :readonly => 'true', :size => '250x10', :value => @val %>

Works as charm.

If you don't want to use the value attribute of textarea you can assign the value in step 1 to the @page.content and it will automatically be inserted as a default value to the form input.

于 2013-01-29T10:36:51.193 回答