Your row_to_update actually is still a relation (which for most purposes behaves like an Array) rather than a single row. It may contain one or more items.
If you are sure your array only contains one item, you can do: row_to_update = History.where("user_id = ? AND question_id = ?", current_user.id, play_list[0][0]).first BTW you can also simplify this query: record = History.where(user_id: current_user, question_id: play_list[0][0]).first if record record.update_attributes(...) end Don't need to do .empty? check because record will be nil if not found, and the if-statement will not evaluate. . On Thursday, July 17, 2014 6:37:52 PM UTC-7, Ruby-Forum.com User wrote: > > Can anyone help with this (I'm a novice). I am trying to update several > attributes in the History table from inside another controller (Drill > controller) > > if !(History.where("user_id = ? AND question_id = ?", current_user.id, > play_list[0][0])).empty? > row_to_update = History.where("user_id = ? AND question_id = ?", > current_user.id, play_list[0][0]) > row_to_update.update_attributes(:date_time => Time.now, :correct => > params[:answeredCorr) > else > ... > > I get the error: > NoMethodError: undefined method `update_attributes' for > #<ActiveRecord::Relation::ActiveRecord_Relation_History:0x00000109d80f40> > from > /Users/dcastellano1/.rvm/gems/ruby-2.1.0/gems/activerecord-4.0.3/lib/active_record/relation/delegation.rb:121:in > > > `method_missing' > > Thank, > Dave Castellano > > -- > Posted via http://www.ruby-forum.com/. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0b1d002e-5001-48bf-9102-93ec3bc54039%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.