我有以下数组
cities = ["Kathmandu", "Pokhara", "", "Dharan", "Butwal"]
Run Code Online (Sandbox Code Playgroud)
我想从数组中删除空白元素,并希望得到以下结果:
cities = ["Kathmandu", "Pokhara", "Dharan", "Butwal"]
Run Code Online (Sandbox Code Playgroud)
有没有像compact这样的方法没有循环?
当我从轨道表格中保存多个红宝石时,它似乎在前面添加了一个空白元素.我该如何删除它?该字段是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"}
Run Code Online (Sandbox Code Playgroud)
调节器
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
Run Code Online (Sandbox Code Playgroud)