Home How to routes to a specific controller with a variable value ahead of it in rails 5?
Reply: 1

How to routes to a specific controller with a variable value ahead of it in rails 5?

vidur punj
1#
vidur punj Published in 2017-11-13 09:07:22Z

Normally its like: resources :users To keep a value ahead we can do like

scope :url do
   resources :users
end

but, issue is that I have the just variable in front of the routes not a fixed value with few conditions for it. Example in rails 2. and want to convert the routing accoding to 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

Thanks in advance.

vidur punj
2#
vidur punj Reply to 2017-11-14 13:21:46Z
scope "/(:subdomain)", :defaults => {:subdomain => "default"} do
  ...
end

use subdomain as a variable.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.33238 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO