I have Addresses
, Lists
, and AddressListMemberships
.
In this particular application there are over a thousand List
s and many thousands of Addresse
s.
I've implemented a UI page to let users control a List
's Address
es. I've added these actions...
class ListsController < ApplicationController
# ...
def add_address
@list = List.find(params[:id])
address = Address.find(params[:address_id])
@list.addresses << address unless @list.addresses.include? address
redirect_to(manage_list_addresses_path(@list))
end
def remove_address
@list = List.find(params[:id])
address = Address.find(params[:address_id])
@list.addresses.delete address
redirect_to(manage_list_addresses_path(@list))
end
end
Everything works beautifully.
However, those actions look like they have too much code in them. I'm guessing there's a more succinct, Railsish way to implement them, particularly this thing...
@list.addresses << address unless @list.addresses.include? address