[英]Template is missing (application cannot find a .js.erb file)
I'm trying to use a create.js.erb templete, located in /app/views/users/ but I get the following error: 我正在尝试使用位于/ app / views / users /中的create.js.erb Templete,但出现以下错误:
Template is missing
Missing template users/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/tim/fairym/app/views"
My controller action, I base it on the following railscast: http://railscasts.com/episodes/381-jquery-file-upload 我的控制器操作是基于以下railscast进行的: http: //railscasts.com/episodes/381-jquery-file-upload
def create
@user = User.create(params[:user])
end
What is the problem here? 这里有什么问题?
It's not expecting a js file. 它不希望有js文件。 Add a respond_to
block to your method: 在您的方法中添加一个respond_to
块:
def create
@user = User.create(params[:user])
respond_to do |format|
format.js
# add more 'format' calls for any other formats this method should ever respond to.
end
end
I know this is already answered, but I had the same problem and error message, and solved it by adding "remote: true" to my form. 我知道已经回答了,但是我遇到了同样的问题和错误消息,并通过在表单中添加“ remote:true”来解决了该问题。 You'll need this whenever submitting an ajax call on a form. 每当在表单上提交ajax调用时,您都将需要此功能。
I know this is obvious to most, but not to newbies like myself who commonly forget these things. 我知道这对大多数人来说是显而易见的,但对于像我这样通常会忘记这些事情的新手却不是。
For example: 例如:
<%= form_for([@club, @club_order], remote: true) do |f| %>
Hope this helps. 希望这可以帮助。
The reason why it cannot find your template is because, if you notice on the railscast episode, he is doing an AJAX request for a datatype of script
它找不到模板的原因是,如果您在railscast情节中注意到,他正在针对script
的数据类型进行AJAX请求
$('#new_painting').fileupload
dataType: "script"
So depending on how you are doing your link to the create action that link probably expects a html format to be rendered. 因此,根据您的操作方式,您可能会希望链接的html格式呈现给create动作。
Template is missing
Missing template users/create, application/create with {:locale=>[:en], **:formats=>[:html]**, :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/home/tim/fairym/app/views"
You can fix this by adding a render js
to your action or if you are doing an ajax request make sure your datatype is set to script. 您可以通过在操作中添加render js
来解决此问题,或者如果您正在执行ajax请求,请确保将数据类型设置为脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.