に行くとhttp://localhost:3000/register_entries/new
、次のエラーが発生します。undefined method `model_name' for NilClass:Class
以下は私の_checkoutform.html.erb
です。この行<% @register_entry = RegisterEntry.new %>
をコントローラーの先頭に追加すると、フォームが表示されますが、送信すると次のエラーが発生しますThe action 'create' could not be found for RegisterEntriesController
。
<%= form_for (@register_entry) do |f| %>
<% if @register_entry.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@register_entry.errors.count, "error") %> prohibited this register from being saved:</h2>
<ul>
<% @register_entry.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :publisher %>
<%= f.collection_select :publisher_id, Publisher.order(:name), :id, :name %>
</div>
<div class="field">
<%= f.label :territory %>
<%= f.collection_select :territory_id, Territory.order(:last_worked), :id, :number %>
</div>
<div class="field">
<%= f.label "Checkout Date" %>
<%= f.date_select :checkout %>
</div>
<!-- <div class="field">
<%= f.label :checkin %><br />
<%= f.date_select :checkin %>
</div> -->
<!-- <div class="field">
<%= f.label :notes %><br />
<%= f.text_field :notes %>
</div> -->
<div class="actions">
<%= f.submit "Checkout Territory" %>
</div>
<% end %>
これが私のregister_entries_controller.rb
:
class RegisterEntriesController < ApplicationController
# GET /RegisterEntries
# GET /RegisterEntries.json
before_filter :authenticate_user!
helper_method :sort_column, :sort_direction
private
def sort_column
@register_entry.column_names.include?(params[:sort]) ? params[:sort] : "checkout"
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
end
def index
authorize! :index, @user, :message => 'Not authorized'
@register_entries = RegisterEntry.order(sort_column + ' ' + sort_direction) #pluralized @register_entry
respond_to do |format|
format.html # index.html.erb
format.json { render json: @register_entries }
end
end
# GET /RegisterEntries/1
# GET /RegisterEntries/1.json
def show
@register_entry = RegisterEntry.find(params[:id])
@publishers = Publisher.all
respond_to do |format|
format.html # show.html.erb
format.json { render json: @register_entry }
end
end
# GET /RegisterEntries/new
# GET /RegisterEntries/new.json
def new
@register_entry = RegisterEntry.new
authorize! :index, @user, :message => 'Not authorized'
respond_to do |format|
format.html # new.html.erb
format.json { render json: @register_entry }
end
end
# GET /RegisterEntries/1/edit
def edit
authorize! :index, @user, :message => 'Not authorized'
@register_entry = RegisterEntry.find(params[:id])
end
# POST /RegisterEntries
# POST /RegisterEntries.json
def create
authorize! :index, @user, :message => 'Not authorized'
@register_entry = RegisterEntry.new(params[:register_entry])
respond_to do |format|
if @register_entry.save
format.html { redirect_to @register_entry, notice: 'Register Entry was successfully created.' }
format.json { render json: @register_entry, status: :created, location: @register_entry }
else
format.html { render action: "new" }
format.json { render json: @register_entry.errors, status: :unprocessable_entity }
end
end
end
# PUT /RegisterEntries/1
# PUT /RegisterEntries/1.json
def update
authorize! :index, @user, :message => 'Not authorized'
@register_entry = RegisterEntry.find(params[:id])
respond_to do |format|
if @register_entry.update_attributes(params[:register_entry])
format.html { redirect_to @register_entry, notice: 'Register Entry was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @register_entry.errors, status: :unprocessable_entity }
end
end
end
# DELETE /RegisterEntries/1
# DELETE /RegisterEntries/1.json
def destroy
authorize! :index, @user, :message => 'Not authorized'
@register_entry = RegisterEntry.find(params[:id])
@register_entry.destroy
respond_to do |format|
format.html { redirect_to register_entries_url }
format.json { head :no_content }
end
end
end
これと数時間戦ってきました。何か案は?