ruby-on-rails – Mysql2 ::错误:第1行的列’描述’的数据太长
发布时间:2020-12-17 01:30:31 所属栏目:百科 来源:网络整理
导读:我正在使用文本编辑器(wysi html5).我在数据库中保存数据时遇到问题.如果我输入的行数超过20行.它显示错误,如“Mysql2 ::错误:第1行的列’描述’的数据太长了.”我正在使用rails4. 在模型中 class News ActiveRecord::Base attr_accessible :name,:publishe
我正在使用文本编辑器(wysi
html5).我在数据库中保存数据时遇到问题.如果我输入的行数超过20行.它显示错误,如“Mysql2 ::错误:第1行的列’描述’的数据太长了.”我正在使用rails4.
在模型中 class News < ActiveRecord::Base attr_accessible :name,:published_on,:description #associations validates :name,presence: true validates :published_on,presence: true validates :description,presence: true end 在控制器中 class NewsController < ApplicationController layout :setting_layout before_action :set_news,only: [:show,:edit,:update,:destroy] # GET /news # GET /news.json def index @news = News.all end # GET /news/1 # GET /news/1.json def show end # GET /news/new def new @news = News.new end # GET /news/1/edit def edit end # POST /news # POST /news.json def create @news = News.new(news_params) respond_to do |format| if @news.save format.html { redirect_to @news,notice: 'News was successfully created.' } format.json { render action: 'show',status: :created,location: @news } else format.html { render action: 'new' } format.json { render json: @news.errors,status: :unprocessable_entity } end end end # PATCH/PUT /news/1 # PATCH/PUT /news/1.json def update respond_to do |format| if @news.update(news_params) format.html { redirect_to @news,notice: 'News was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @news.errors,status: :unprocessable_entity } end end end # DELETE /news/1 # DELETE /news/1.json def destroy @news.destroy respond_to do |format| format.html { redirect_to news_index_url } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_news @news = News.find(params[:id]) end # Never trust parameters from the scary internet,only allow the white list through. def news_params params.require(:news).permit(:name,:description) end end 在视图中 <%= simple_form_for @news,html: {class: 'form-inline form-horizontal'},:validate => true do |f|%> <p><font color="red">Fields with * are required.</font></p> <div class="inputs"> <%= f.input :name %> <%= f.input :published_on,as: 'string',input_html: {class: 'datepicker'} %> <%= f.input :description,as: 'text',:input_html =>{:rows => '100',:cols => '100',:class => 'input wysihtml5' }%> </div> <div class="form-actions"> <%= button_tag(type: 'submit',class: "btn btn-primary") do %> <i class="icon-ok icon-white"></i> Save <% end %> </div> <% end %> 在Js文件中 $(document).ready(function(){ $(".wysihtml5").wysihtml5(); }) 在视图中我给出了row和cols值.但它只需要cols值. 解决方法
您可能已将其设置为迁移文件中的字符串,而不是文本. 字符串字段被解释为varchar,并且字符长度有限.文本字段不是.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |