Consider this helper method:
module SomeHelper
def display_button
Foo.find_by_id params[:id] and Foo.find(params[:id]).organizer.name != current_name and Foo.find(params[:id]).friends.find_by_name current_name
end
end
How to refactor into something more readable?
Rails 3.2.2
You can factorize the call to
Foo.find(params[:id])and useexists?for the third conditionYou can also create several methods to gain on reusability (and will save trouble if you model changes):