私の backbone.js ビューの 1 つに、次のコードがあります。
events:
'click .filter_classroom_size': 'filterClassroom'
filterClassroom: (event)->
event.stopPropagation()
event.preventDefault()
Backbone.history.navigate("classrooms?nationality", true)
私のルーターには次のコードがあります。
routes:
'classrooms?:filter': 'classrooms'
initialize: ->
@collection = new Classrooms.Collections.Entries()
@collection.fetch()
classrooms: (filter) ->
classroomView = new Seats.Views.ClassroomIndex(collection: @collection)
$('#output_container').html(classroomView.render().el)
alert("#{filter}") # this prints out the filter parameter
教室_コントローラー.rb:
class ClassroomsController < ApiController
def show
# How do I send a parameter here so I can filter on it?
respond_with Classroom.all
end
end
データベースの結果をフィルタリングできるように、パラメーターをコントローラーに渡すことができるようにしたいと考えています。
ありがとう!