从下面的代码中,如何从 Ember.js 路由器调用我的 Rails AssetsController 的自定义路由“dynamicSearch”?
导轨侧:
控制器 > assets_controller.rb
class AssetsController < ApplicationController
#caches_page :index
# GET /assets
# GET /assets.json
def index
begin
params[:foo] ||= "bar"
assets = Asset.all(params: {foo: params[:foo]})
respond_to do |format|
format.html # index.html.erb
format.json { render json: assets }
end
end
end
def dynamic_search
params[:bar] == "bar"
assets = Asset.all(params: {bar: params[:bar]})
respond_to do |format|
format.json { render json: assets }
end
end
end
Ember.js 路由 - 动态搜索是从 Ember 视图中的按钮调用的操作。
assets: Em.Route.extend({
route: '/assets',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('assets', router.get('store').findAll(App.Asset));
},
dynamicSearch: function(router) {
// How do I connect this to my Assets#dynamicSearch route in the Rails controller?
},
index: Ember.State.extend({
route: '/',
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('assets');
}
})
}) // assets route