首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wysihtml5在rails中无法正常工作

wysihtml5在rails中无法正常工作
EN

Stack Overflow用户
提问于 2013-08-02 12:40:45
回答 1查看 357关注 0票数 2

我遇到了wysihtml5编辑器的麻烦(用于引导)。它只需要三行代码,并去掉了其他代码行。当我在编辑器中给出10行代码时。它只需要三行代码。所以只保存了三行。

在视图(_form.html.erb)中:

代码语言:javascript
复制
<%= simple_form_for @announcement, :html => { :class => 'form-horizontal' } do |f| %>
  <%= f.input :name %><br/>
  <%= f.input :description, as: 'text', :input_html =>{:rows => '25', :cols => '25', :class => 'input wysihtml5' } %>
  <div class="input string optional"><label class="string optional control-label" for="school_school_name">Upload Logo</label> 
    <%= f.fields_for :pictures do |i| %>
      <%= i.file_field :avatar %>
    <% end %></div><br/>
  <div class="form-actions">
    <%= f.button :submit, :class => 'btn-primary' %>
    <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                announcements_path, :class => 'btn' %>
  </div>
<% end %>

模型:

代码语言:javascript
复制
include ActionView::Helpers::SanitizeHelper
class Announcement < ActiveRecord::Base
  attr_accessible :description, :name,  :pictures_attributes


  #association
  has_many :pictures, :as => :imageable
  accepts_nested_attributes_for :pictures, allow_destroy: :true


   #before_save :strip_html  

end

控制器:

代码语言:javascript
复制
class AnnouncementsController < ApplicationController
  # GET /announcements
  # GET /announcements.json
  def index
    @announcements = Announcement.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @announcements }
    end
  end

  # GET /announcements/1
  # GET /announcements/1.json
  def show
    @announcement = Announcement.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @announcement }
    end
  end

  # GET /announcements/new
  # GET /announcements/new.json
  def new
    @announcement = Announcement.new
    @announcement.pictures.build

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @announcement }
    end
  end

  # GET /announcements/1/edit
  def edit
    @announcement = Announcement.find(params[:id])
  end

  # POST /announcements
  # POST /announcements.json
  def create
    @announcement = Announcement.new(params[:announcement])

    respond_to do |format|
      if @announcement.save
        format.html { redirect_to @announcement, notice: 'Announcement was successfully created.' }
        format.json { render json: @announcement, status: :created, location: @announcement }
      else
        format.html { render action: "new" }
        format.json { render json: @announcement.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /announcements/1
  # PUT /announcements/1.json
  def update
    @announcement = Announcement.find(params[:id])

    respond_to do |format|
      if @announcement.update_attributes(params[:announcement])
        format.html { redirect_to @announcement, notice: 'Announcement was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @announcement.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /announcements/1
  # DELETE /announcements/1.json
  def destroy
    @announcement = Announcement.find(params[:id])
    @announcement.destroy

    respond_to do |format|
      format.html { redirect_to announcements_url }
      format.json { head :no_content }
    end
  end
end

运行wysihtml5的JS脚本

代码语言:javascript
复制
$(document).ready(function(){
    $(".wysihtml5").wysihtml5();    
})
EN

回答 1

Stack Overflow用户

发布于 2013-09-25 18:15:41

我的猜测是因为您的属性在数据库中设置为错误的类型。您可能将其作为字符串而不是文本,因此它会自动截断它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18008899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档