web - Rails3使用form_for時出現undefined method `*_path’錯誤。
問題描述
使用rails g controller admin::articles index new edit創建controller,使用rails g model article創建的model。 路由為
namespace :admin do resources :articlesend
/app/controllers/admin/articles_controller.rb
class Admin::ArticlesController < ApplicationController def index @articles = Article.all end def new @article = Article.new end def edit @article = Article.find(params[:id]) end
/app/models/article.rb
class Article < ActiveRecord::Base attr_accessible :content, :tag, :titleend
現在想要在new.html.erb使用form_for創建一個表單
<%= form_for(@article) do |f| %><p class='field'> <%= f.label :title %><br /> <%= f.text_field :title %></p><% end %>
結果還只到這里測試的時候就出現了錯誤undefined method `articles_path’,麻煩大家幫忙看看是哪里出了問題。
問題解答
回答1:[:admin, @article]http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces
相關文章:
1. docker 17.03 怎么配置 registry mirror ?2. webpack - vue-cli寫的項目(本地跑沒有問題),準備放到Nginx服務器上,有什么配置需要改的?還有怎么部署?3. java - 如何用圖畫的方式有效地表示多線程?4. javascript - js對象 屬性的訪問和創建5. css - Flexbox 怎么實現多行多列6. css - 多個div顯示橫向滾動條7. 微信開放平臺 - ios APP能不能打開微信然后通過微信跳轉到指定的URL?8. javascript - H5移動端開發9. windows-server - 登入遠程桌面(windows桌面)以后,怎么在Linux環境下跑python程序?10. node.js - 為什么npm安裝vue-cli會出現下面的錯誤??!!!?
