【发布时间】:2014-12-28 01:52:47
【问题描述】:
我有一个简单的 Angular Rails 应用程序,我正在尝试连接它。
这是我的 Rails 控制器:
class ItemsController < ApplicationController
respond_to :json, :html
def index
@items = Item.order(params[:sort]).page(params[:page]).per(15)
end
def show
@item = Item.where(params[:id])
if @item.empty?
flash[:alert] = "Item number #{params[:id]} does not exist"
else
respond_with @item do |format|
format.json { render :layout => false }
end
end
end
end
我不断收到ActionView::MissingTemplate 错误,因为 rails 一直在尝试提供 erb 模板。我不要模板!!我只想要json。有人能给出明确的respond_to/respond_with语法吗?可以让我永远摆脱模板吗?
【问题讨论】:
标签: ruby-on-rails json activerecord controller respond-with