2017-06-02 54 views
-4

我做了如下介紹: http://guides.rubyonrails.org/getting_started.html沒有路線匹配[POST]「/ articles/new」 - 爲什麼?

在這之後,我想創造一個新的領域(如標題),並得到了錯誤的通知:

這裏是我的代碼:

路線.RB

Rails.application.routes.draw do 
    get 'welcome/index' 

    resources :articles do 
    resources :comments 
    resources :description 
    root 'welcome#index' 

    # For details on the DSL available within this file, see guides.rubyonrails.org/routing.html 
    end 
end 

我知道這個問題已經被問了很多,但他們的解決方案並沒有幫助我。

我該怎麼辦?

問候

+0

顯示你的'config/routes.rb'文件。 – yzalavin

+0

您需要添加更多詳細信息才能讓人們獲得幫助。例如,一切正常工作,直到您開始進行更改以添加新字段?如果是這樣,請描述您所做的更改。此外,何時出現此錯誤? – mikej

+0

這裏是檔案 Rails.application.routes.draw do get 'welcome/index' resources :articles do resources :comments resources :description root 'welcome#index' # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end end 而且我確實改變了new.html.erb文件。我添加了一個新的f.label和f.textarea – neverbesuccesfulllperson

回答

0

默認情況下軌的新資源路線有GET HTTP動詞,不是POST。除非你另有說明。

0

好像你正在使用new_article_patharticles/new形式

<%= form_for :article, url: new_articles_path do |f| %> 

將其更改爲

<%= form_for :article, url: articles_path do |f| %> 
0

的問題是在你的new.html.erb形式,你缺少url: articles_path,如果你不指定它,表單將被髮送到相同的動作(即new)。所以,既然提交表單使用POST(默認)方法,您可以:

沒有路由匹配[POST]「/篇/新」

你需要改變你的form_for並指定url,像這樣:

<%= form_for :article, url: articles_path do |f| %> 

same link您提供:

雖然這個表單有一個問題。如果您檢查生成的HTML ,通過查看頁面的源代碼,您將看到 表單的動作屬性指向/ articles/new 。 這是一個問題,因爲此路徑轉到目前正確的 的頁面,並且該路線只能用於顯示新文章的表格 。

我強調