14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/registrations_controller.rb', line 14
def create
if @address.valid?
@areas = @address.closest_regions
if @areas.empty?
flash[:alert] = "Sorry, we couldn't find any neighbourhoods close to you!"
redirect_to root_path
else
@selected_area = @areas.shift
@address.area_id = @selected_area.id
@user = User.new(:address_attributes => @address)
@user.memberships.build(:area_id => @selected_area.id)
end
else
flash[:alert] = "Please enter a valid address"
redirect_to root_path
end
rescue ActiveRecord::StatementInvalid
flash[:alert] = "Sorry, we couldn't find the address you specified"
redirect_to root_path
end
|