Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 正在进行编辑验证,但创建Rails时缺少模板错误错误_Ruby On Rails_Ruby_Forms_Validation_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 正在进行编辑验证,但创建Rails时缺少模板错误错误

Ruby on rails 正在进行编辑验证,但创建Rails时缺少模板错误错误,ruby-on-rails,ruby,forms,validation,ruby-on-rails-4,Ruby On Rails,Ruby,Forms,Validation,Ruby On Rails 4,我使用的是rails 4.1.4和ruby 2.1.2。我是RubyonRails编程新手。我在验证表单时发现模板丢失错误。相同的代码用于编辑,但在创建新帖子时显示此错误。这是我为博客创建/编辑文章的代码(我的第一个测试RoR应用程序) 控制员: class PostsController < ApplicationController def index @posts = Post.all end def show @post = Post.find(par

我使用的是rails 4.1.4和ruby 2.1.2。我是RubyonRails编程新手。我在验证表单时发现模板丢失错误。相同的代码用于编辑,但在创建新帖子时显示此错误。这是我为博客创建/编辑文章的代码(我的第一个测试RoR应用程序)

控制员:

class PostsController < ApplicationController
  def index
    @posts = Post.all
  end

  def show
    @post = Post.find(params[:id])
  end

  def new
    @post = Post.new
  end

  def create
    @post = Post.new(post_params)

    if @post.save
        redirect_to posts_path, :notice => "Your Post was saved"
    else
        render new
    end
  end

  def post_params
    params.require(:post).permit(:title, :content)
  end

  def edit
    @post = Post.find(params[:id])
  end

  def update
    @post = Post.find(params[:id])

    if @post.update_attributes(post_params)
        redirect_to posts_path, :notice => "Post updated successfully"
    else
        render "edit"
    end
  end

  def destroy
    @post = Post.find(params[:id])
    @post.destroy
    redirect_to posts_path, :notice => "Your post has been deleted"
  end
end

提前谢谢

您的问题就在这里:

render new
它正在执行
new
方法,该方法返回一个新的post实例,因此其内容如下:

render Post.new
当render获取模型时,它尝试为其渲染部分视图,因此它正在寻找
\u post
部分视图,该视图显然不存在。您需要的是:

render :new

我认为当你发布有问题的
edit.html.erb
时出现了一些问题。一旦您的操作重定向到索引操作,请检查它。在
posts/index.html.erb
中,您提到了一个
render partial:“post”
。你能在这里发布index.html.erb的代码吗?不相关,但应该有
render:new
,而不是
render new
。更新:事实上,我认为这就是问题所在。我会把答案贴出来。
  Template is missing
  Missing partial posts/_post with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in: * "/home/sandesh/blog/app/views"
render new
render Post.new
render :new