【发布时间】:2017-12-20 13:17:39
【问题描述】:
首先我要承认我对 Rails 很陌生。尽管我过去在 Rails 方面有过成功的记录,但我遇到了一个无法解决的错误。这是以下错误:
缺少带有 {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb, :html 的模板 /ctoneposts , :builder, :ruby, :coffee, :jbuilder]}。
奇怪的是,在我的代码停止工作之前,我能够使用 form_for 创建帖子。我有两个帖子可以在我的网络应用程序中动态添加。在此之后,我添加了 devise gem 并开始将用户分配到帖子的过程(在我进行测试之前一切都很好!)
这是我的控制器:
class CtonepostsController < ApplicationController
def index
@ctoneposts = Ctonepost.all
@ctoneposts = Ctonepost.order(created_at: :desc)
end
def create
post_params = params.require(:ctonepost).permit(:content)
@ctonepost = Ctonepost.new(content: post_params[:content])
if @ctonepost.save
redirect_to ctoneposts_path
else
render ctoneposts_path
end
end
end
我收到有关渲染 ctoneposts_path 的错误。
这是我的 index.html.erb 文件:
<%= render "ctoneform" %>
<br>
<%= render @ctoneposts %>
_ctonepost.html.erb:
<div class="col-xs-8">
<p><%= ctonepost.content %></p>
<small><%= ctonepost.created_at.strftime("%b %d, %Y") %></small>
</div>
我的观点是片面的。我做了一些改变(我不记得我做了什么),它最终吐出了一个部分视图错误。我什至在更改文件保存的内容等方面走了这么远,但似乎没有任何效果,它是快把我逼疯了!请帮助新的 Ruby on Rails 编码器!
【问题讨论】:
标签: ruby-on-rails post devise