Does the method work in the console but not in the controller?
SORRY :: I forgot that params [: user_id] doesn't exist in the controller using current_user.id!
I wrote a method that returns an array of custom bid location values, such as [2, 8, 10]. In the Rails console, it works fine, but the controller instance variable returns nil to the browser. What's happening?
This method returns an array such as [1, 2, 3] from 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 the debugger)
@user_places = @bid.bid_places(params[:user_id], params[:auction_id])
=> []
source to share
be careful, you can probably see that the script / console interactivity tells you more than what's actually going on in your method.
The question is: does your method actually return something? try to explicitly define the refund and see if it works for you?
script / console (and irb) often do STDOUT evaluations that return things to you that don't actually return, to offer additional debugging help.
source to share