Dynamic Views

Hello Folks,

And thanks to everyone so far who has answered my newbie questions :slight_smile:

I just want a little advice, I'm starting tinkering with ruby to show certain businesses locations which reside in a city.

Firstly the user chooses a country, from that country I can find all the cities in that country. Then the chooses a city, and from the user chooses a company and from that we can display all the locations for that business in the city. I have all the data working, I completely understand how the models should look and the relationships within them, but I just would like some opinions on how it should fir together.

So I have Countries, Cities, Businesses, Locations

The easiest way is to have one 'show' view for countries - which lists all countries. (say the route is /Countries/show/) The you could click a country and it would have a new view for all the cities ( route is Countries/US/Show). So then we have a view which shows all the businesses in that city lets (route is Countries/US/MIA/Show), you then select company AL And finally you have a view which shows the locations of that business for the chosen company in the city (route is /Countries/US/MIA/AL/Show).

Which is all well and good - does the job but it goes through 4 seperate pages, what would be much nicer is to have one single view, which would load each subsection as the data became available? does that make sense ? so instead of 4 views you would have one which each time it got the additional data it would load a new section. So questions are.

1) Is this feasible (I think it must be). 2) How do you route it so that it effectively uses the same top level 'view' 3) I'm assuming it would use partials, and if so would these need to be called in a if statement or is there a more elegant way of doing it? 4) This also sounds quite a nice exercise to do in a AJAX way - can anyone give me any pointers on where to look at AJAX examples for ruby?

Again thanks for the help and sorry if my newbie questions have been asked before!

Look at this:

http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html

AJAX is the way to go in my opinion and you can always fall back to HTML. Also take a look at the casts about AJAX on railscasts.com, which pretty much got me started.