簡體   English   中英

有沒有辦法在 Ruby on Rails routes.rb 中定義沒有“/new”的新動作的路徑?

[英]Is there a way to define path of new action without '/new' in Ruby on Rails routes.rb?

有沒有辦法通過編寫resources在 Ruby on Rails routes.rb定義沒有 '/new' 的新動作的路徑?

我想將/p/e/:article_id的頁面定義為popular/contacts#new操作。

然后,我寫在下面。

namespace :popular, path: 'p' do
  resources :contacts, only: [:new], path: 'e/:article_id'
end

然而,上面的結果是這樣的。

new_popular_contact GET   /p/e/:article_id/new(.:format)    popular/contacts#new

如果可能,我想使用resources ,但我別無選擇,只能使用如下get而不是resources

namespace :popular, path: 'p' do
  get '/e/:article_id' => 'contacts#new'
end

謝謝

您可以更改路徑名,如下所示:

scope(path_names: { new: 'neu', edit: 'bearbeiten' }) do
  resources :categories, path: 'kategorien'
end

參考: https : //guides.rubyonrails.org/routing.html#translated-paths

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM