web - Rails3使用form_for時出現undefined method `*_path'錯誤。
PHPz
PHPz 2017-04-21 11:16:38
0
1
953

使用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',麻煩大家幫忙看看是哪裏出了問題。

PHPz
PHPz

学习是最好的投资!

全部回覆(1)
迷茫

[:管理員,@文章] http://guides.rubyonrails.org/form_helpers.html#dealing-with-namespaces

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板