ActionView :: MissingTemplate尝试创建新对象时出错

时间:2014-06-18 20:54:21

标签: ruby-on-rails json templates coffeescript actionview

我遇到错误“ActionView :: MissingTemplate(Missing template home / suites,application / suites with {:locale => [:en],:formats => [:json],:handlers => [:erb,:builder,:coffee,:haml,:rabl]}。“当我试图发布(创建新的)套件(/suites.json)时。代码片段在下面。

有人可以告诉我如何解决这个问题吗?谢谢!

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

enter image description here

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)

1 个答案:

答案 0 :(得分:1)

create方法结束时,您需要redirect_to将用户发送到其他页面(例如edit.html.erb)。如果您不这样做,控制器将POST数据,然后尝试呈现一个无法找到的create.html.erb页面。