2016-02-25 59 views
1

我在rails項目中使用TinyMce gem,我試圖調整編輯器的寬度。目前,編輯有100%的寬度。在Ruby on Rails中調整tinymce編輯器的寬度

我讀的地方,即TinyMCE的編輯器取area_field的大小,所以我嘗試這樣的:根據行值

<%= f.text_area :content, :cols =>10, :rows => 50, class: "tinymce" %> 

高度變化,但寬度撐全屏。我implented TinyMCE的在軌使用本教程:https://richonrails.com/articles/adding-tinymce-to-your-rails-application

我注意到,在該tinymce.yml文件中,有兩條線,即提全屏:

theme_advanced_toolbar_location: top 
theme_advanced_toolbar_align: left 
theme_advanced_statusbar_location: bottom 
theme_advanced_buttons3_add: 
    - tablecontrols 
    - fullscreen 
plugins: 
    - table 
    - fullscreen 

但我無法弄清楚,是什麼我需要改變,以調整編輯器的寬度。任何建議?提前致謝!

編輯:

我將此添加到我的相關博客文章:

<script> 
tinyMCE.init({ 
     // General options 
     mode: "textareas", 
     theme: "advanced", 
     width: "300", 
     height: "200", 

     // Theme options 
     theme_advanced_buttons1: "bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull", 
     theme_advanced_buttons2: "", 
     theme_advanced_buttons3: "", 
     theme_advanced_buttons4: "", 
     theme_advanced_toolbar_location: "top", 
     theme_advanced_toolbar_align: "left", 
     theme_advanced_resizing: false, 

    // Selector 
     editor_selector: "tinymce", 

}); 
</script> 

,然後,我的編輯消失。我哪裏做錯了?

回答

1

這裏是一個示例代碼,用於調整寬度並很好地居中tinymce。只需將寬度(此處= 400px)設置爲所需的大小即可。

<div class="field"> 
    <%= f.label :content %><br /> 
    <div style="width: 400px"> 
     <%= f.text_area :content, :class => "tinymce", :rows => 3 %> 
    </div> 
</div>