SORRY:: I forgot that params[:user_id] does not exist in the controller, using current_user.id !
I wrote a method that returns an array of place values for user bids, e.g., [2, 8, 10]. In the Rails console it works fine, but the instance variable from the controller returns nil to the browser. What's going on?
This method returns an array such as [1, 2, 3] from the console
def bid_places(bid_user_id, auction_id)
unique_bids = Bid.find_all_by_auction_id(auction_id).uniq
unique_bids.sort! {|a, b| b.point <=> a.point }
a, n, places = 0, 0, []
until a == 3 || n == unique_bids.count
place = n + 1
user = unique_bids.values_at(n).first.user_id
if user == bid_user_id
places[a] = place
a += 1
end
n += 1
end
places
end
in the controller, this returns [] (using debugger)
@user_places = @bid.bid_places(params[:user_id], params[:auction_id])
=> []