Rails3使用form_for时出现undefined method `*_path'错误。
使用
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| %>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<% end %>
结果还只到这里测试的时候就出现了错误undefined method `articles_path',麻烦大家帮忙看看是哪里出了问题。
xzuu7
11 years, 4 months ago
Answers
[:admin, @article] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces
地精工程学徒
answered 11 years, 4 months ago