Reputation: 12431
I am hitting the error "ActionView::MissingTemplate (Missing template home/suites, application/suites with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :haml, :rabl]}." when I tried to post (create new) to suites (/suites.json). The snippets of codes are below.
Can anyone advise me on how I can resolve this? Thanks!
SuitesController.rb
def create
@suite = Suite.new
@suite.text = params[:suite][:text]
@suite.description = params[:suite][:description]
@suite.remote_image_url = params[:suite][:image_url]
if @suite.save
render json: Suite.standard_to_json(@suite)
else
render json: @suite.errors, status: :unprocessable_entity
end
end
Suites.rb
class Suite
include Mongoid::Document
include Mongoid::Timestamps
field :text, type: String
field :description, type: String
field :image_url, type: String
mount_uploader :image, ImageUploader
validates_presence_of :text
validates_presence_of :image
def self.standard_to_json(suites)
suites.to_json
end
end
Suites.js.coffee
class Entities.Suite extends Backbone.Model
urlRoot: "/suites"
class Entities.SuitesCollection extends Backbone.Collection
model: Entities.Suite
url: "/suites"
API =
getSuites: (cb) ->
suites = new Entities.SuitesCollection
suites.fetch
success: ->
cb suites
error: ->
cb suites
newSuite: (suite, cb) ->
$.post "/suites.json",
suite: suite
.success (suite) ->
cb (suite)
App.reqres.setHandler "suites:get", (cb) ->
API.getSuites(cb)
App.reqres.setHandler "suite:add", (suite , cb) ->
API.newSuite(suite, cb)
Upvotes: 0
Views: 680
Reputation: 4049
At the conclusion of your create
method, you need to have a redirect_to
that sends the user to a different page (e.g., an edit.html.erb
). If you don't do this, the controller will POST the data, and then try to render a create.html.erb
page, which it can't find.
Upvotes: 1