新手问题 参照官方教材写 blog,格式问题请教

justend · 2013年04月21日 · 最后由 justend 回复于 2013年04月21日 · 6828 次阅读

当在 create post 后,无论原始输入的格式如何,在 posts/show 显示是格式都没了,连到一起,如何保留格式呢

谢谢

HTML 被转义了吧?在 post 正文后面加个 html_safe.

<%= @post.content.html_safe %>

刚才加上试了一下,还不行,还有可能是什么 问题呢?

controller 中的 create 这样写的


def create
  @post = current_user.posts.build(params[:post])

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

post/show

= @post.content.html_safe

不是 html safe 要用simple_format @content

#3 楼 @cqcn1991 可以了,多谢:)

需要 登录 后方可回复, 如果你还没有账号请 注册新账号