使用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| %> <%= f.label :title %>
<%= f.text_field :title %>
<% end %>
结果还只到这里测试的时候就出现了错误undefined method `articles_path',麻烦大家帮忙看看是哪里出了问题。
[:admin, @article] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces