009994c3985985809d2d644bd49aa1c2

url_for 與 nested routes 跟 namespaced models

lulalalaRuby on Rails 節點 中發起
最後由 lulalala回應 , 168次閱讀

我有以下三個 models

Article

Article::Line (lines of the article)

Article::Review (reviews of a line)

我想要做出來的 routes 是像

/articles/11/line/2/review/new

/articles/11/line/2/review/edit

我的 route.rb

resources :articles do
scope module: 'article' do
resources :lines do
resources :reviews
end
end
end

我想讓 form_for (其實就是url_for)自動判斷產生 create或是 update path:

<%= form_for [ @line.article, @line, @review ] do |f| %>

不過 url_for 看到這種方式就頭昏了,給我: undefined method 'article_article_line_article_reviews_path' 錯誤.

我那邊要修改才能做出來正確的 url_for 呢?還是這是url_for 做不出來的?

P.S.
markdown parser 好像壞了,用block code就會出現問題

截至 ,共收到 2 條回應
Ff7afae5b23125e25e18ad8c0404bd78
hechian 1樓, 於回應

<%= form_for [ @line.article, :article, @line, @review] %> 這樣呢?

009994c3985985809d2d644bd49aa1c2
lulalala 2樓, 於回應

找到解法了:http://github.com/rails/rails/issues/1429 需要複寫 model_name 方法,也許有後遺症不過我還沒有遇到問題。

需要 登入 後方可回應,如果你還沒有帳號按這裡 註冊