当我从 ruby on rails 表单中保存多项选择时,它似乎在前面添加了一个空白元素。如何删除它?该字段是 selected_player。
{"utf8"=>"✓",
"authenticity_token"=>"H8W7qPBezubyeU0adnTGZ4oJqYErin1QNz5oK0QV6WY=",
"schedule"=>{"event"=>"1",
"result_id"=>"",
"time"=>"26/10/2012",
"duration"=>"15",
"arrival_time"=>"14",
"location_id"=>"25",
"selected_players"=>["", "38", "41"],
"team_id"=>"1",
"opponent_id"=>"7",
"home_or_away"=>"Home"},
"commit"=>"Save Event"}
控制器
def update
@schedule = Schedule.find(params[:id])
@user = User.find(current_user)
@players = User.where(:team_id => current_user[:team_id]).all
respond_to do |format|
if @schedule.update_attributes(params[:schedule])
Notifier.event_added(@user,@schedule).deliver
format.html { redirect_to(@schedule,
:notice => "#{event_display_c(@schedule.event)} vs #{@schedule.opponent.name} was successfully updated.") }
format.json { head :no_content }
else
format.html { render :action => "edit" }
format.json { render :json => @schedule.errors, :status => :unprocessable_entity }
end
end
end