整个下午,
我有一个帖子模型,它有一个歌曲名称、歌曲字符串字段和一个 user_id 字段。用户可以创建最多 10,000 个字符的新歌曲。现在,当保存一首短歌时,它可以完整地显示它,但是当用户输入一首长歌说超过 400 个字符时,它似乎将其中的大部分内容切断,只显示大约 200 个字符,编辑时也会发生同样的情况,添加这首歌的遗骸,它仍然切断它。数据库是 Mysql 并在控制台中检查,它似乎也没有保存完整的条目。歌曲以键盘格式编写,例如 ETWR[TREW] | 威尔。我有一个谷歌并没有找到任何类似的东西。
我的代码如下;
post.rb
class Post < ActiveRecord::Base
attr_accessible :song, :song_name, :user_id, :rating
has_many :comments, dependent: :destroy
has_many :ratings, dependent: :destroy
belongs_to :user
before_save :rating
validates_presence_of :user_id
validates :song_name, presence: true, length: { maximum: 70 }
validates :song, presence: true, length: { maximum: 10000 }
default_scope order: "posts.created_at DESC"
post_controller.rb
def show
@post = Post.find(params[:id])
@comments = @post.comments
@ratings = @post.ratings
respond_to do |format|
format.html
format.json { render json: @post }
end
end
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @post }
end
end
def edit
@post = Post.find(params[:id])
end
def create
@post = current_user.posts.build(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to @post, success: 'Post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new", error: "please sign in to post" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to @post, success: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit", error: "please try again" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end
和 show.html.erb
<div class="center hero-unit">
<h1><%= @post.song_name %></h1>
<p>Transcript by: <%= @post.user.name %><br/>
Rating: <%= @post.rating %>/10</p>
<br/>
<p><%= raw @post.song %></p>
<br/>
<span class="timestamp">
updated <%= time_ago_in_words(@post.updated_at) %> ago.
</span>
<%= link_to 'Edit', edit_post_path(@post) %>
<br/>
<% if !signed_in %>
please login to rate songs
<% else %>
<%= render partial: "ratings/form", locals: { post_id: @post.id }%>
<% end %>
</div>
<%= render partial: "comments/form", locals: { post_id: @post.id } %>
<%= render partial: "comments/show", locals: { comments: @comments, post_id: @post.id } %>
如果有人有任何想法,将不胜感激,如果您需要更多代码,请询问。欢呼安迪。