我總是收到此錯誤信息:動作控制器:異常|未定義的方法`fetch_value '的零:NilClass
NoMethodError在ListsController#新未定義的方法`fetch_value' 的零:NilClass
提取的源(左右線#8 ):
7 DEF新
8 @list = List.new
9端
我沒有得到這個錯誤的原因^^
我的routes.rb
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
root 'lists#index'
get 'home' => 'lists#index', as: 'home'
get 'new' => 'lists#new', as: 'new'
resources :lists
end
數據庫名稱:
:列出
型號名稱:
列表
lists_controller:
class ListsController < ApplicationController
def index
@lists = List.all
end
def new
@list = List.new
end
def show
@list = List.find(params[:id])
end
def create
@list = List.new(list_params)
if(@list.save)
redirect_to @list
else
render 'new'
end
end
def edit
@list = List.find(params[:id])
end
def update
@list = List.find(params[:id])
if(@list.update(list_params))
redirect_to @list
else
render 'edit'
end
end
def destroy
@list = List.find(params[:id])
@list.destroy
redirect_to lists_path
end
private def list_params
params.require(:list).permit(:date, :class, :lesson, :subject, :teacher, :room, :info)
end
end
new.html.erb
<%= form_for :list, url: lists_path do |f| %>
<% if @list.errors.any? %>
<% @list.errors.full_messages.each do |error| %>
<div class="alert alert-danger"><%= error %></div>
<% end %>
<% end %>
<div class="alert alert-info">Please fill out all the fields below.</div>
<p>
<%= f.label :date %><br>
<%= f.text_field :date, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :class %><br>
<%= f.text_area :class, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :lesson %><br>
<%= f.number_field :lesson, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :subject %><br>
<%= f.text_field :subject, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :teacher %><br>
<%= f.text_field :teacher, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :room %><br>
<%= f.text_field :room, {:class => 'form-control'} %>
</p>
<p>
<%= f.label :info %><br>
<%= f.text_area :info, {:class => 'form-control'} %>
</p>
<p>
<%= f.submit({:class => 'btn btn-info'}) %>
</p>
<% end %>
使用BootstrapCDN只有默認的寶石。
感謝您的任何答案:)
我不確定,但是您可以嘗試從'form'中刪除'class'屬性的標籤和文本區域,並且不應該使用已經保留的'class'類名稱。 – Deep