I’m trying to update some data in database but I’m getting this error:
undefined method `is_current' for #<ActiveRecord::Relation:0x38622a8>
My controller:
@user = User.where("user_id = #{user_id} and is_current = 1")
if @user.nil?
puts"xxxxxxxxxxxxxxxxxxxxxxxxxxx"
else
@user.is_current = 0
@user.to = Time.now
@user.save
end
User.where returns an array. You need to say .first afterwards. Additionally do not use a string in where with out escaping your arguments. Your query is not secure and is open to SQL injection.