Ruby on rails Rails自定义路由映射不正确

Ruby on rails Rails自定义路由映射不正确,ruby-on-rails,reactjs,Ruby On Rails,Reactjs,我正在向另一个控制器发出ajax请求,但路由有问题。这是我的请求:(使用react.js) 我已经把这个放在我的路线上了。rb: get 'allRooms', to: 'rooms#allRooms' 现在,allRooms是我在rooms\u控制器中定义的一种方法 但是,当触发请求时,该请求将获得此url:http://localhost:3000/houses/allRooms 这通电话是从我家管制员的show view中拨打的 为什么我的请求不能正确地路由到房间控制器?(我多次重新

我正在向另一个控制器发出ajax请求,但路由有问题。这是我的请求:(使用react.js)

我已经把这个放在我的路线上了。rb:

  get 'allRooms', to: 'rooms#allRooms'
现在,
allRooms
是我在
rooms\u控制器中定义的一种方法

但是,当触发请求时,该请求将获得此url:
http://localhost:3000/houses/allRooms

这通电话是从我家管制员的show view中拨打的


为什么我的请求不能正确地路由到房间控制器?(我多次重新启动rails服务器)

尝试将js代码更改为:

$.ajax({
  type: 'GET',
  url: '/allRooms',
  dataType: 'json',
  success:function(data){
    this.setState({data:data});
  }.bind(this)
});

一种方法是将url分配给全局配置,并在调用请求时使用它。例如,您可以在生成页面时附加到
window.App.configuration.url.AllRoomsUrl=“#{all_rooms\u url}”
,然后在调用ajax调用时,通过
window.App.configuration.url.AllRoomsUrl
$.ajax({
            type: 'GET',
            url: 'http://localhost:3000/allRooms',
            dataType: 'json',
            success:function(data){
                this.setState({data:data});
            }.bind(this)
        });
$.ajax({
  type: 'GET',
  url: '/allRooms',
  dataType: 'json',
  success:function(data){
    this.setState({data:data});
  }.bind(this)
});