What is the best approach to do this?
@user = UserFinder.find(first_name: "Dave")
if !@user
return render :text => '// No user named Dave found'
end
if @user.last_name != "Edwards"
# This is not the guy we want
@user.destroy
# Now we want to re-execute the search again forever until we find Dave Edwards
end
Keep in mind this is an incredibly simplistic example of the real code I have, so I know that I can just filter the query in the first place, but I want it this way.
I’m not sure how to do this with begin and while blocks because destroying an unwanted user is required if we run into one.
My Attempts:
begin
@user = UserFinder.find(first_name: "Dave")
return render :text => '// No user named Dave found'
end while @user.destroy if @user.last_name != "Edwards"
This doesn’t work because the while block gets the result of destroy not the comparison of last_name
P.S. Just if this is impossible this way, How to reload the Rails controller action with the same params?
Try this: