こんにちは私はルビーレールの学生です。私は自分のデータベースに保存するものを作成しようとしています。私はそれを働かせることはできません。私が作成したイベントボタンをクリックするとイベントコントローラーがデータベースに保存されていません
class EventsController < ApplicationController
def index
@events = Event.all
end
def show
@event = Event.find(params[:id])
end
def new
@event = Event.new
end
def create
@event = Event.new(event_params)
if @event.save
redirect_to event_index
else
render 'new'
flash[:notice] = "Event not saved"
end
それは何もしません。
<h1>Create your Event</h1>
<%= form_for @event do |f| %>
<div>
<%= f.label :name %>:
<%= f.text_field :name %><br />
</div>
<div>
<%= f.label :description %>:
<%= f.text_field :description %><br />
</div>
<div>
<%= f.label :location %>:
<%= f.text_field :location %><br />
</div>
<div>
<div class="field">
<%= f.label :date%>
<%= f.date_select :date,
{ order: [:month, :day, :year],
prompt: [ day: 'Select day', month: 'Select month', year: 'Select year' ]} %>
</div>
<br>
<%= f.submit %>
<% end %>
はここに私のコントローラである:
は、ここに私のフォームページです。レールコンソールで
私のスキーマ
create_table "events", force: :cascade do |t|
t.string "name"
t.string "description"
t.date "date"
t.string "location"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
私はこれを参照することができます:
IRB(メイン):001:0> Event.all イベントロード(4.9ms)は、「イベントを選択」。* FROM "イベント" =># IRB(メイン):002:0>
問題の原因となった場合のために、あなたのコントローラにevent_paramsを投稿することをお勧めします。 – Ren
また、アクションのログを含みます... – 7urkm3n