1

I have a single page website using ruby on rails as the framework. On the single page I have a

header

section 1

section 2

section 3 etc

footer

The problem I am having is this, how do I organise the layouts/views/controllers. Only in one section I have a form which needs processing and is linked to a database table (model). Can anyone advise me on how I can organise my ROR application?

Muhammed Bhikha
  • 4,881
  • 9
  • 36
  • 47

2 Answers2

7

The question on "how to make a single-page application in Rails" has been asked numerous times on SO like here, here and here.

You can try to look for Single Page Application (SPA) tutorials and there is a video on Vimeo here where Prateek Mohan Dayal shows off how to make a single-page application in Rails and Backbone.js.

On Back-End of an SPA

On the backend side you're most likely going to arrange your controllers and models the same way as usual with Rails, but you'll be retrieving JSON-data as views (i.e. AJAX stuff) as they're the easiest way to handle data client-side.

So think about what models you have and how you're going to work with them in controllers an arrange the code as usual.

As to how to do things AJAXy with sending JSON data to and from Rails you can have a look at Yehuda Katz Rails 3 book in this SO answer or you could have a look at this simple example that uses Rabl to develop a JSON API.

On Front-End of an SPA

It seems that most Rails developers are using either Backbone.js or Ember.js for single page application development. Both of them have some powerful javascript based view-model and databinding concepts which helps out developing the web app.

Another way to get started is to look at Addi Osmani's TodoMVC project that is a single page application (i.e. a web based todo-list) developed in many different javascript MVC frameworks. Both frameworks mentioned above are available for your perusal:

Here are some screencasts:

Community
  • 1
  • 1
Spoike
  • 119,724
  • 44
  • 140
  • 158
1

Well, if you don't create a new layout, everything is going to be in the application layout (app/views/layous/application.html.erb), in this file you're going to create you html for the header and the foother. Also in this file you'll see a <%= yield %>, this yield is going to show you view of your controller.

Sorry about my english, I hope this help you. Also you could check the Rails Tutorial

is very helpful and very descriptive. Also you could check the RailsCast videos.

For the section 1 and section 2 you could check the rails guide to undertand how to show something in any numbers of yields. Here is the link Understanding yield

Jean
  • 5,201
  • 11
  • 51
  • 87