Rails 5:由页面路由阻止的rails-jquery-autocomplete路由

时间:2018-03-09 14:49:11

标签: jquery ruby-on-rails ruby autocomplete routes

我使用rails-jquery-autocomplete gem(https://github.com/bigtunacan/rails-jquery-autocomplete)和Rails 5来使我的数据库搜索自动完成。不幸的是,我的房源模型已经存在的路线似乎正在干扰我现在试图建立的路线。

listings_controller.rb:

final Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(Calendar.DAY_OF_MONTH, ogirinal.get(Calendar.DAY_OF_MONTH));
cal.set(Calendar.MONTH, ogirinal.get(Calendar.MONTH));
cal.set(Calendar.YEAR, ogirinal.get(Calendar.YEAR));

routes.rb中:

autocomplete :listing, :community, full:true, :extra_data => [:subdivision]

通过get '/listings/:listing_id/:address/:mls', to: 'listings#show', as: 'listing' post 'listings/:listing_id', to: 'clients#textme', as: 'new_text_client' resources :listings do get :autocomplete_listing_community, :on => :collection end 传递所有三条路线:

resources: :listings do

当我运行ArgumentError: Invalid route name, already in use: 'listings' You may have defined two routes with the same name using the `:as` option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with `resources` as explained here: http://guides.rubyonrails.org/routing.html#restricting-the- routes-created 时。但是,如图所示,这样做:

rake routes

如何将这些全部合作?

1 个答案:

答案 0 :(得分:0)

您可以except使用resources,然后就可以使用

get '/listings/:listing_id/:address/:mls', to: 'listings#show', as: 'listing'

resources :listings, except: [:show] do
    get :autocomplete_listing_community, :on => :collection
end

将此视为rake routes

                            listing GET    /listings/:listing_id/:address/:mls(.:format)      listings#show
                        new_text_client POST   /listings/:listing_id(.:format)                    clients#textme
autocomplete_listing_community_listings GET    /listings/autocomplete_listing_community(.:format) listings#autocomplete_listing_community
                               listings GET    /listings(.:format)                                listings#index
                                        POST   /listings(.:format)                                listings#create
                            new_listing GET    /listings/new(.:format)                            listings#new
                           edit_listing GET    /listings/:id/edit(.:format)                       listings#edit
                                        PATCH  /listings/:id(.:format)                            listings#update
                                        PUT    /listings/:id(.:format)                            listings#update
                                        DELETE /listings/:id(.:format)                            listings#destroy