简体   繁体   English

Rails app中缺少模板/部署到Heroku时创建POST操作

[英]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.

相关问题 部署到 Heroku 的 Rails 应用程序出现 NoMethodError(在模型上调用.create 时) - NoMethodError with Rails app deployed to Heroku (When calling .create on model) 尝试使用Factory Girl在我的Rails应用程序中测试用户登录时,创建操作时缺少模板错误 - Missing template error on create action when trying to use factory girl to test user logins in my rails app Rails应用程序在本地运行,但在部署到Heroku时则不行 - Rails app works locally but not when deployed to Heroku Rails App可在本地运行,但在Heroku上部署时无法运行 - Rails App works locally but not when deployed on Heroku 在Heroku中使用Webpack部署Rails应用程序时出错 - Error when deployed the rails app with webpack in the Heroku 使用travis部署Rails项目时,heroku中缺少图像 - images are missing in heroku when rails project is deployed using travis 如何让用户在Heroku上部署的Rails应用程序中创建计划任务 - How to have users create scheduled tasks in rails app deployed on Heroku 将Rails应用程序部署到Heroku无法正常工作 - Deployed rails app to Heroku not working 部署到Heroku时,Rails App崩溃,但是日志声称一切正常 - Rails App crashes when deployed to Heroku, but logs claim everything is fine 将Rails应用程序部署到heroku时出了点问题 - Something went wrong when rails app deployed onto heroku
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM