LoginSignup
1
1

More than 5 years have passed since last update.

url_forにてnamespaceの異なるコントローラーのアクションをURLをフルパスで指定する方法

Posted at

ユーザ側から管理画面へのURLをフルパスで表示したいのだが、
意外とハマったので、備忘録としてメモ。

routes.rb

scope :admin do
  resources :inquiries, only: [:show]
end

管理画面へのroutes

# rake routes | grep inquiries
admin_inquiry_path  GET /admin/inquiries/:id(.:format)  admin/inquiries#show

ユーザ側で表示するには、下記でOK

<%= url_for(admin_inquiry_path @id, host: 'localhost', only_path: false, protocol: :http, port: (Rails.env.development? ? 3000 : nil)) %>

[参考URL]
http://stackoverflow.com/questions/20057910/rails-url-for-behaving-differently-when-using-namespace-based-on-current-cont
http://apidock.com/rails/ActionController/Base/url_for

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1