【问题标题】:How to routes to a specific controller with a variable value ahead of it in rails 5?如何在rails 5中路由到具有变量值的特定控制器?
【发布时间】:2017-11-13 09:07:22
【问题描述】:

通常是这样的: 资源:用户 为了保持价值,我们可以这样做

scope :url do
   resources :users
end

但是,问题是我在路线前面有一个变量,而不是一个固定值,它的条件很少。 rails 2中的示例。并希望将路由编码转换为rails5

map.with_options :controller => 'users' do |user|
  user.forgot_user ':url/users/forgot',   :action => 'forgot',  :url => /([a-zA-Z0-9\-]*)/
  user.user ':url/users/retrieve',   :action => 'retrieve',  :url => /([a-zA-Z0-9\-]*)/
  user.login       ':url/users/login',    :action => 'login',                                          :url => /([a-zA-Z0-9\-]*)/
  user.logout      ':url/users/logout',   :action => 'logout',                                         :url => /([a-zA-Z0-9\-]*)/
  user.new_user    ':url/users/new',      :action => 'new',     :conditions => { :method => :get },    :url => /([a-zA-Z0-9\-]*)/
  user.users       ':url/users/:id',      :action => 'show',   :conditions => { :method => :get },    :url => /([a-zA-Z0-9\-]*)/
end

提前致谢。

【问题讨论】:

  • 你的意思是“问题是我在路由前面有just变量不是固定值”解释更多

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-5 ruby-on-rails-5.1


【解决方案1】:
scope "/(:subdomain)", :defaults => {:subdomain => "default"} do
  ...
end

使用子域作为变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 2017-02-12
    • 1970-01-01
    • 2023-03-14
    • 2017-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多