R
R
Ruslan Galiev2014-07-18 08:15:25
Ruby on Rails
Ruslan Galiev, 2014-07-18 08:15:25

Rails ActionView::MissingTemplate how to fix error?

Hello
From time to time an error occurs in the project:

ActionView::MissingTemplate: Missing template mobile_synchronization/orders, application/orders with {:locale=>[:ru], :formats=>[:json], :handlers=>[:erb, :builder]}. Searched in:
* "/var/www/mss/releases/20140717080253/app/views"
* "/var/www/mss/shared/bundle/ruby/1.9.1/gems/twitter-bootstrap-rails-2.2.6/app/views"
* "/var/www/mss/shared/bundle/ruby/1.9.1/gems/devise-2.2.4/app/views"
* "/var/www/mss/shared/bundle/ruby/1.9.1/gems/kaminari-0.14.1/app/views"

Rails is trying to find a view file for a json request, of course there is no file, in the controller just in response to a POST request
POST http://server.com/synchronization/orders.json
Gives a response:
respond_to do |format|
            if @order.save
              @responce = JSON code: 100, description: 'created successfully'
              format.json { render json: @responce, status: :created, location: @order }
            else
              @responce = JSON code: 200, description: 'the data format is not valid'
              format.json { render json: @responce, status: :unprocessable_entity }
            end
          end

Those. no view files should be rendered, explain to me why the server is trying to look for them?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Perzh, 2014-07-18
@Perzh

I'm no rails expert, but it seems that every controller should have a view by default. Maybe it's worth creating an empty view and rendering it with an option layout: false # нивелируем добавление layout
. When I gave html on ajax request, I did something similar, though my view was not empty.

@
@proffard, 2014-07-21
_

Check this case:
maybe users right click on server.com/synchronization/orders.json link and select "open in new tab"

A
Andrew Emelianenko, 2014-07-22
@YourWest

Try to write this code in the controller to always force JSON rendering:
respond_to :json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question