Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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
like image 816
schleg Avatar asked Nov 17 '11 23:11

schleg


2 Answers

It's not supposed to render anything?

Do you have render :nothing => true in your action?

like image 88
Francisco Soto Avatar answered Sep 23 '22 03:09

Francisco Soto


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. 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. 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. 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.

like image 23
Tara Roys Avatar answered Sep 22 '22 03:09

Tara Roys