Input on application design

I have an online doctor/dentist search. Right now I have all the code
in one controller, with separate views and actions for the doctor and
dentist. About 80% of the code in both the controller and the view is
shared. Doctors and dentists are in separate tables with different
(yet very similiar) schema’s. So the sql queries are different, and
some of the information displayed in the view is different.

I’ve been trying to figure out the best way to keep each search in
it’s own controller instead of combining everything into one. I want
to avoid having to update both controllers when some shared piece of
code changes. Right now i have just one controller for both searches,
and the views use the generic @search and @search_pages instead of say
@dentist and @dentist pages. I’ve done a quick outline of how my
controller now work below. I’d really like to do this in separate
controllers, but I’m wondering where is the best place to put the
shared code in a situation like this.

def physician # action for physician search
search
end

def dentist # action for dentist search
search
end

def search

shared code

if params[:address] or params[:page]
if params[:action] == ‘physician’
@search_pages,@search = physician_search
elsif params[:action] == ‘dentist’
@search_pages,@search = dentist_search
end
end

more shared code

More action specific code

more shared code

repeat a couple more times

end

Yes, you can just put the shared code in it’s own method
(search_init) in application_controller.rb. Then, just call the
common method from the specific search controllers.

        - dan


Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000