未定义的局部变量或方法错误

时间:2012-10-24 10:35:10

标签: ruby-on-rails ruby ruby-on-rails-3

在我的ruby on rails项目中,我在update中发现了这个错误。

undefined local variable or method ` ' for #<ProfileController:0x007fd904dc8568>.

但是,我在控制器中找不到(`')

ProfileController可#更新

def update       
   unless params[:sport_name].nil? 
     ps_array = params[:sport_name]
     level =[params[:level1],params[:level2],params[:level3]]
     # play_sports id 
     sp_id = [params[:sp_id1], params[:sp_id2], params[:sp_id3]]

     arr = [ps_array["1"],ps_array["2"],ps_array["3"]]
     sport_id = [params[:sport_id1],params[:sport_id2],params[:sport_id3]]
     check = [params[:check1], params[:check2], params[:check3]]

     if @user.play_sports.count != 0

       (0..2).each do |i|
           if (check[i].to_i == 1)
           PlaySport.where("id = ?", sp_id[i]).update_all(:is_active=>false)
           # new save 
           newuser_ps = PlaySport.new
           newuser_ps.sport_id = arr[i]
           newuser_ps.is_active = true
           newuser_ps.level = level[i]
           newuser_ps.user_id = current_user.id
           newuser_ps.save
         end
       end
     else         
       (0..2).each do |i|    
         newuser_ps = PlaySport.new
         newuser_ps.sport_id = arr[i]
         newuser_ps.level = level[i]
         newuser_ps.is_active = true
         newuser_ps.user_id = current_user.id
         newuser_ps.save
       end
     end        
   end


   respond_to do |format|        
   end
end

1 个答案:

答案 0 :(得分:2)

这可能是一个看不见的空间,但红宝石没有。通过在合适的编辑器中选择文本进行检查,该编辑器将显示它们是空格还是其他。