使用rails g controller admin::articles index new edit
創建controller,使用rails g model article
創建的model。 路由為
namespace :admin do
resources :articles
end
/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, :title
end
現在想要在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',麻煩大家幫忙看看是哪裏出了問題。
迷茫2017-04-21 11:18:38
[:管理員,@文章] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces