web - Rails3使用form_for时出现undefined method `*_path'错误。
PHPz
PHPz 2017-04-21 11:16:38
0
1
839

使用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',麻烦大家帮忙看看是哪里出了问题。

PHPz
PHPz

学习是最好的投资!

reply all (1)
迷茫

[:admin, @article] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!