[英]backbone on rails collection fetch does not work except in javascript console
[英]Collection fetch with parameter does not act in Backbone Rails
我現在正在開發Backbone + Rails應用程序,不知道為什么集合中的URL設置不起作用。
這是細節。
class Entities.Tab extends App.Entities.Model
#urlRoot: -> Routes.tabs_path()
class Entities.TabsCollection extends App.Entities.Collection
model: Entities.Tab
url: -> Routes.tabs_path()
API =
getCheckedTabs: ->
tabs = new Entities.TabsCollection
"url": ->
Routes.tabs_path recordKey: App.recordKey
tabs.fetch
reset: true
tabs
我的routes.rb文件在下面。
Rails.application.routes.draw do
resources :records
resources :tabs
get 'tabs/:recordKey/checked' => 'tabs#checked'
我的tabs_controller.rb文件在下面。
class TabsController < ApplicationController
include TabsHelper
respond_to :json
def index
if params[:recordKey]
@record = Record.find_by key: params[:recordKey]
debugger
@tabs = []
(1..4).each do |index|
tab_array = binary_maker @record.instance_variable_get("group_#{index}")
tab_array.each do |order_in_group|
tab = Tab.find_by(group_id: index, order_in_group: order_in_group)
@tabs.insert(tab)
end
end
@tabs
else
debugger
@tabs = Tab.all
end
end
def checked
debugger
params[:recordKey]
end
end
當我通過運行getCheckedTabs函數調試該應用程序時,我注意到調用了tabs / index操作的else語句,但是如果要使用tab / index操作的一部分,則我要的是第一個語句;如果之前的操作是不可能的,那么我想要的是第一個。
你能幫我嗎???
通過顯式的url插入,我可以解決此問題。
那是,
tabs.url = Routes.tabs_path recordKey: App.recordKey
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.