RailsCast #415 ( http://railscasts.com/episodes/415-upgrading-to-rails-4?view=asciicast )に従って、Rails アプリを Rails 3.2.8 から Rails 4.0.0 にアップグレードしています。強力なパラメータにアップグレードします。強力なパラメーターを使用するようにイベントコントローラーを更新した後、フォームを送信して新しいイベントを作成できます (検証エラーはスローされません) が、送信されたすべてのパラメーターは null であり、ターミナルログ (ローカルで実行) は次のように述べています。
WARNING: Can't mass-assign protected attributes for Event: street, description, host_name, event_date(1i), event_date(2i), event_date(3i), event_time(1i), event_time(2i), event_time(3i), event_time(4i), event_time(5i), event_name, end_time(1i), end_time(2i), end_time(3i), end_time(4i), end_time(5i)
明らかに、私は大量割り当ての問題を抱えており、強力なパラメータが適切に機能していません。
イベント コントローラーには、次のプライベート メソッドがあります。
private
def event_params
params.require(:event).permit(:city, :state, :street, :zip, :description,
:host_name, :host_contact, :event_date, :event_time,
:instructions, :event_name, :end_time)
end
event#create アクションは次のようになります (足場で作成):
def create
@event = Event.new(event_params)
respond_to do |format|
if @event.save
format.html { redirect_to @event, notice: 'Event was successfully created.' }
format.json { render json: @event, status: :created, location: @event }
else
format.html { render action: "new" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
gemfile には、移行中に使用する次の gem が含まれています: gem 'protected_attributes'
また、application.rb ファイルでは、whitelist_attributes が false に設定されています (コメントアウトされています)。
# config.active_record.whitelist_attributes = true
ここで点をつなぐために私が欠けているものについての助けは役に立ちます。ありがとう。