问题描述
我使用的轨道4和angularjs。我跟着railscast()教程。在轨道3教程。
问题是,我得到当我试图从数据库中查询数据的错误。以下是错误GET本地主机:3000/406项(不接受)。我的事我的角度code是可以正常使用,可能是这个问题是在我的控制器。因为当我使用本地主机:3000 /项的链接,我得到这个错误的ActionController :: UnknownFormat在EntriesController#指数
控制器:
类EntriesController< ApplicationController中
respond_to代码:HTML,:JSON 高清指数
respond_with Entry.all
结束
结束
角:
应用程序= angular.module(Raffler,[ngResource])app.factory进入,[$资源,($资源) - GT;
$资源(/项/:ID,{ID:@id},{更新:{方法:PUT}})
]
@RaffleCtrl =$范围,输入,($范围,进入) - GT;
$ scope.entries = Entry.query()
]
查看:
< DIV NG控制器=RaffleCtrl>
<形式NG提交=的addEntry()>
<输入类型=文本NG模型=newEntry.name>
<输入类型=提交值=添加>
< /表及GT; < UL>
<李NG重复=条目中的条目>
{{entry.name}}
<跨度NG秀=entry.winnerNG-CLASS ={亮点:进入== lastWinner}级=赢家>&WINNER LT; / SPAN>
< /李>
< / UL> <按钮NG点击=drawWinner()>抽奖< /按钮>
< / DIV>
添加到您的路由配置
资源:项,默认:{格式:'JSON'}
I am using rails 4 and angularjs. I am follow railscast(http://railscasts.com/episodes/405-angularjs) tutorial. The tutorial on rails 3.The problem is that I am getting an error when I am trying to query data from database. Here is the error "GET localhost:3000/entries 406 (Not Acceptable)". I thing my angular code is working perfectly and may be the problem is in my controller. Because when I am using "localhost:3000/entries" link, I am getting this error "ActionController::UnknownFormat in EntriesController#index".
Controller:
class EntriesController < ApplicationController
respond_to :html, :json
def index
respond_with Entry.all
end
end
angular:
app = angular.module("Raffler", ["ngResource"])
app.factory "Entry", ["$resource", ($resource) ->
$resource("/entries/:id", {id: "@id"}, {update: {method: "PUT"}})
]
@RaffleCtrl = ["$scope", "Entry", ($scope, Entry) ->
$scope.entries = Entry.query()
]
view:
<div ng-controller="RaffleCtrl">
<form ng-submit="addEntry()">
<input type="text" ng-model="newEntry.name">
<input type="submit" value="Add">
</form>
<ul>
<li ng-repeat="entry in entries">
{{entry.name}}
<span ng-show="entry.winner" ng-class="{highlight: entry == lastWinner}" class="winner">WINNER</span>
</li>
</ul>
<button ng-click="drawWinner()">Draw Winner</button>
</div>
Add this to your routes config
resources :entries, defaults: { format: 'json' }
这篇关于在angularjs轨道4 406(不接受)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!