关于 ruby??:Rails 更改路线系统 | 珊瑚贝

Rails change route system


我是初学者 Rails 开发人员。我有这个问题:
我的路线中有资源。
资源

1
2
3
4
5
6
  resources :events, only: [:index, :show, :comment] do
    member do
      post :comment
      get :will_go
    end
  end

然后在事件模型中我有这个关系
事件属于城市
在城市模型中
城市有_许多事件

我使用friendly_id gem,来做我自己的路线。现在我有指向事件的链接,例如:
http://localhost:3000/events/moscow/concert_of_madonna/49
在哪里
莫斯科 – 是城市的名称
Concert_of_madonna – 是事件标题的蛞蝓
49 是事件 ID

但是我们需要做这样的事情:
http://localhost:3000/moscow/events/concert_of_madonna/49
所以我需要切换城市名称和资源。

我知道我可以通过路由做到这一点,但我没有成功。

我能做什么?


我认为您正在寻找的是 scope:

1
2
3
4
5
6
7
8
scope ‘:city’ do
  resources :events, only: [:index, :show, :comment] do
    member do
      post :comment
      get :will_go
    end
  end
end

来源:https://www.codenong.com/35695644/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9487.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?