在我的一个backbone.js 视图中,我有以下代码:
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
我希望能够将参数传递给控制器,以便过滤数据库结果。
谢谢!