[英]Missing Template in Rails app on /create POST action when deployed to Heroku
I'm experience some very strange behavior with a Rails app on Heroku. 我在Heroku上使用Rails应用程序遇到了一些非常奇怪的行为。 Basically, I'm doing a very straightforward post in a controller and it's failing with a missing template exception.
基本上,我在一个控制器中做了一个非常简单的帖子,它失败了,缺少模板异常。 For the life of me I can't figure out why this built-in controller action would expect a template (??).
对于我的生活,我无法弄清楚为什么这个内置的控制器动作会期望一个模板(??)。 The strange thing is this works just fine locally--the exception only occurs on the deployed app.
奇怪的是,这在本地工作得很好 - 例外只发生在部署的应用程序上。 This is all I'm getting back from the Heroku logs.
这就是我从Heroku日志中回来的全部内容。
Started POST "/camps" for ............ at 2011-11-17 23:27:47 +0000
ActionView::MissingTemplate (Missing template camps/create, application/create with
{:handlers=>[:erb, :builder, :haml], :formats=>[:html], :locale=>[:en, :en]}. Searched in:
* "/app/app/views"
* "/app/vendor/bundle/ruby/1.9.1/gems/kaminari-0.12.4/app/views"
* "/app/vendor/bundle/ruby/1.9.1/gems/devise_invitable-0.5.7/app/views"
* "/app/vendor/bundle/ruby/1.9.1/gems/devise-1.4.9/app/views"
):
cache: [POST /camps] invalidate, pass
It's not supposed to render anything? 它不应该渲染任何东西?
Do you have render :nothing => true
in your action? 你的行动中有
render :nothing => true
吗?
If it's anything like the issue I just had, the problem is that for some reason rails doesn't know where to go after it gets done processing your post request. 如果它与我刚刚遇到的问题类似,那么问题是由于某些原因,rails在处理完您的帖子请求后不知道该去哪里。 Here's some code of mine that created exactly the same error:
这是我的一些代码,它们创建了完全相同的错误:
def create
if params[:favorite] == true
current_user.favorite == true
else
redirect_to root_url
end
end
The problem is that if the first part of the if statement was true, I set the a the user favorite property to true. 问题是如果if语句的第一部分为true,我将用户最喜欢的属性设置为true。 Then I did nothing.
然后我什么也没做。 I forgot to inform rails where to go next.
我忘了通知铁路下一步去哪里。 Rails continued on to the bottom of the create method, and found nowhere to go, so it thought I must have defined a default create template, and went looking for that.
Rails继续在create方法的底部,发现无处可去,所以它认为我必须定义一个默认的创建模板,然后去寻找它。 When it didn't find one, it basically turned to me and said, "Where the heck am I supposed to go next?
当它没找到一个时,它基本上转向我说:“我到底应该去哪儿?
The fixed code is as follows. 固定代码如下。
def create
if params[:favorite] == true
current_user.favorite == true
end
redirect_to root_url
end
In this fixed code, regardless of how the if statement turns out, I still told rails that it is supposed to go to the root route, aka my homepage, after it gets done with this method. 在这个固定的代码中,无论if语句如何结束,我仍然告诉rails它应该在完成这个方法之后进入根路由,也就是我的主页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.