Ruby-on-rails 模板丢失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6495046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 01:28:25  来源:igfitidea点击:

Template is missing

ruby-on-rails

提问by David

Currently working on a project, and have encountered a problem that I have never come across before. Currently doing a login sign up page that ask the user to sign up. I had a undefined method `name'error before, and then realised that the method is not called name it was called full_name. I have gone through all the folders to ensure that any method or attribute is not called 'name' and renamed it to 'full_name. Having refreshed the browser I recieve the following error which I haven't seen before. Can some please explain what this error is and how possibly I may go about resolving it.

目前正在做一个项目,遇到了一个我以前从未遇到过的问题。目前正在做一个登录注册页面,要求用户注册。我之前有一个未定义的方法`name'错误,然后意识到该方法不是名为name而是名为full_name。我已经浏览了所有文件夹以确保任何方法或属性都没有被称为“name”并将其重命名为“full_name”。刷新浏览器后,我收到了以前从未见过的以下错误。请一些人解释一下这个错误是什么以及我如何可能去解决它。

Template is missing

Missing template users/create with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "C:/Users/patterd/Documents/Project/app/views"

模板丢失

缺少模板用户/使用 {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} 创建查看路径“C:/Users/patterd/Documents/Project/app/views”

回答by felix

This error happens if you don't redirect in the createmethod of your controller.

如果您不在create控制器的方法中重定向,则会发生此错误。

Are you redirecting in the create method in the controller or rendering the new form, in case of error?

如果出现错误,您是在控制器中的 create 方法中重定向还是渲染新表单?

Without the redirection in the create method in the controller, you need to make a new file called create.html.erb. Usually, after successful creation, you redirect to some other page like shown below

如果没有控制器中 create 方法中的重定向,您需要创建一个名为create.html.erb. 通常,成功创建后,您重定向到其他页面,如下所示

def create
  # some object you want to create
  # if the object.save is fine
  #   redirect_to object
  # else
  #   render new with the errors
  # end
end

回答by Eduardo Xavier

In my case I had to process and render no view.

在我的情况下,我不得不处理并渲染无视图。

def return_payment
  # do lots of stuff

  head :ok
end

回答by Artur79

I had the same problem and the reason was that I left accidentally other empty 'create' method :)

我遇到了同样的问题,原因是我不小心留下了其他空的“创建”方法:)

回答by Kishan Ku. Patel

Generally missing template error occurs -when you don't have view file of that method of controller, or -if a method is just for calculation that does not have any view file, then you must have to render/redirect the method.

通常会发生缺少模板错误 - 当您没有该控制器方法的视图文件时,或者 - 如果一个方法仅用于没有任何视图文件的计算,那么您必须渲染/重定向该方法。

If you do not render or redirect the method, it will search for the view page of current method name (in your case it will search for create.html.erb).So, you have to render/redirect the method.

如果您不渲染或重定向该方法,它将搜索当前方法名称的视图页面(在您的情况下,它将搜索 create.html.erb)。因此,您必须渲染/重定向该方法。

回答by Jhonnatas Alencar

I had the same problem and just added the redirect_to and it worked!

我遇到了同样的问题,只是添加了 redirect_to 并且它起作用了!

def update
    @visitor = Visitor.find(params[:id])
    if @visitor.update_attributes(visitor_params)
       flash[:notice] = "Update ok!"
       redirect_to root_path #just added this line and it worked!
    else
       render 'edit'
    end
end