Getting "ActionView :: MissingTemplate" when rendering a simple json head reaction

In one of my controllers, I have this code:

respond_to do |format|
  format.html{ redirect_to :me, :flash => {:error => t('quest_histories.misc.bad_request')}} and return
  format.json{ head :method_not_allowed } and return
end

      

BUT, when the json request comes in, I get this error:

ActionView::MissingTemplate (Missing template quest_histories/index, application/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/var/www/PMAC_RoR/app/views"

      

This really confuses me because I have similar code in many other controllers and it actually works ... the controller just has to respond with the html header, it doesn't need a template.

+3


source to share


3 answers


Instead of "and return", remove them and place the result after the whole response_to block.



+4


source


Try adding this:



render :nothing => true

      

+2


source


respond_to do |format|
  format.html{ redirect_to :me, :flash => {:error => t('quest_histories.misc.bad_request')}} and return
  format.json  { render :nothing => :true, :status => :no_content }
end

      

0


source







All Articles