che*_*sen 7 ruby-on-rails ruby-on-rails-3
在我的应用程序中,我将HTML输入保存为"页面",如下所示:
def create
@page = Page.new(page_params)
@page.unique = loop do
random_unique = SecureRandom.urlsafe_base64(4)
break random_unique unless Page.where(unique: random_unique).exists?
end
@page.save
redirect_to "/#{@page.unique}"
end
Run Code Online (Sandbox Code Playgroud)
但如果你在标签中包含功能,它会说它呈现了页面,但实际上它什么也没有返回,URL栏显示'data:,'
奇怪的是,如果您找到@ page.unique,然后访问它,例如localhost:3000/SKkFrA页面呈现正常.
有什么建议?
ps这是我正在使用的show方法:
def show
@page = Page.find_by(unique: params[:id])
render :text => @page.html
end
Run Code Online (Sandbox Code Playgroud)