Samuel Jansson
Samuel Jansson

Reputation: 327

Collection fetch with parameter does not act in Backbone Rails

I am now developing Backbone + Rails app and can't know why url setting in collection does not act.

Here is the detail.

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

And my routes.rb file is below.

Rails.application.routes.draw do
  resources :records
  resources :tabs
  get 'tabs/:recordKey/checked' => 'tabs#checked'

My tabs_controller.rb file is below.

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

When I debug this app by getCheckedTabs function running, I notice the else statements of tabs/index action invoked, but what I want is the first if part of tabs/index action or tabs/checked action if the prior one is not possible.

Would you please help me???

Upvotes: 0

Views: 29

Answers (1)

Samuel Jansson
Samuel Jansson

Reputation: 327

By explicit url insertion, I could solve this problem.

That is,

tabs.url = Routes.tabs_path recordKey: App.recordKey

Upvotes: 1

Related Questions