使用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',麻烦大家帮忙看看是哪里出了问题。
[:관리자, @article] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces