views:

21

answers:

2

I'm creating a rails app with two columns. On one side is a journal log and the other is a set of various links and resources to internal pages. I'd like to be able to navigate to different pages of the journal log on the left side without changing the content on the right. I'd also like to navigate through pages on the right without changing what day of the log is being viewed.

This is very much like two separate html frames. Is there a proper way to do this in rails using rails routing?

+1  A: 

Basically in rails, the best way to do such things is to create a partial and share it whatever pages you want. Partials are small bits of html code which can be reused and rendered.

For example, the navigation can be made into partial and placed into the common layout file. That way it does change for any page using that layout.

http://guides.rubyonrails.org/layouts_and_rendering.html

Read above for more details

Rishav Rastogi
A: 

If you need to replace just a section of one page without causing the whole page to reload, the modern solution is AJAX. (AJAX is the new frames, basically.) There's a whole science to this, but at a high level what you typically do is this:

  • Create links with JavaScript - or otherwise invoke JavaScript functions when necessary, e. g. at intervals - that poll the server for raw data.
  • Set up a controller action that can detect whether the request is a traditional HTTP request or XHR. In Rails, you can either use request.xhr? or a respond_to block, the latter being somewhat more idiomatic.
  • Return a node of HTML that your frontend JavaScript knows how to insert into the page programmatically (render a partial), or return raw data through JSON that your frontend JavaScript can wrap in HTML and insert appropriately (render :json).

This can be complicated, but a Google search for jQuery and AJAX will point you in the right direction.

Raphomet