次のエラーが発生し続けますが、日時を指定して日付と時刻を組み合わせるために使用されるいくつかの仮想属性を宣言しようとしています。以下のコード例からわかるように、属性を設定する方法と、属性に渡す情報を教えてください。
ActiveModel::MassAssignmentSecurity::Error in SchedulesController#create
{"utf8"=>"✓",
"authenticity_token"=>"j4V6DAqK5U/+ZGaSKDlrEoOBqXu3pEq/FM51ingi2sg=",
"schedule"=>{"event"=>"1",
"result_id"=>"",
"date"=>"04/11/2012",
"arrival_time"=>"08:00 PM",
"time"=>"08:00 PM",
"duration"=>"1800",
"location_id"=>"11",
"selected_players"=>["",
"41",
"38"],
"team_id"=>"1",
"opponent_id"=>"1",
"home_or_away"=>"Home"},
"commit"=>"Save Event"}
コントローラ
# POST /schedules
# POST /schedules.json
def create
params[:schedule].delete(:date)
params[:schedule].delete(:time)
@user = User.find(current_user)
@players = User.where(:team_id => current_user[:team_id]).all
params[:schedule][:selected_players].compact
#params[:schedule][:selected_players].reject!{|selected_players| selected_players==""}
#@availabilities = @user.availabilities.create(:unique_id => params[:schedule][:id])
@schedule = Schedule.new(params[:schedule])
respond_to do |format|
if @schedule.save
#Notifier.event_added(@user,@schedule).deliver
format.html { redirect_to(schedules_url,
:notice => "#{event_display_c(@schedule.event)} vs #{@schedule.opponent.name} was successfully created.") }
format.json { render :json => @schedule, :status => :created, :location => @schedule }
else
format.html { render :action => "new" }
format.json { render :json => @schedule.errors, :status => :unprocessable_entity }
end
end
end
モデル
class Schedule < ActiveRecord::Base
belongs_to :location
belongs_to :opponent
belongs_to :team
belongs_to :result
has_many :availabilities, :dependent => :destroy
attr_accessible :location_id, :user_id, :opponent_id, :datetime, :score_for, :score_against, :event,
:team_id, :home_or_away, :arrival_time, :duration, :selected_players, :result_id
attr_accessor :date, :time