Op deze pagina vindt u een aantal problemen waarvoor Suares & Co oplossingen zocht.
Technology
On this page some solutions we found for some uncommon issues.
Using AJAX and link_to_remote with tabnav widgets in Ruby on Rails.
15-08-2008
Using AJAX and link_to_remote with tabnav widgets in Ruby on Rails.
I couldn't find much documentation on this topic, and after some trial and error, I came up with this. Of course you need the tabnav plugin, which is in widgets by Seesaw.
First, you need a partial in views/widgets. I called mine 'detail', so the partial is named '_detail_tabnav.rhtml' (Mind the underscores!).
render_tabnav :detail, :generate_css => false do
add_tab do |t|
t.named 'name'
t.titled 'title'
t.links_to_remote
:update => "detail_tabnav_content",
:url => { :controller => :some_controller,
:action => :some_action,
:id => @record.id }
end
end
I had to supply the id of the record to the controller/action, but for test purposes you might just remove that line to make things less complicated.
In layouts/index.rhtml, I have something like this:
<html>
<head>
... all the head stuff
</head>
<body>
... some body stuff
<div class="detail" id="detail">
<% tabnav :detail do %>
... some stuff maybe...
<% end %>
</div>
</body>
</html>
I think it's possible to just say '<% tabnav :detail %>' and skip the 'do...end' part, but I have some other stuff in between, so let's leave that in there.
What took me so long to understand, was that the widget creates a div called 'detail_tabnav_content' all by itself, and that that is the one you need to refer to in the :update part of links_to_remote. At first, I had made my own div, and used that in the :update part, but that just resulted in the word 'Loading...' in that div, but the content never showed up.
How to get rid of the 'Loading...' message. When your updates don't take that long, the word 'Loading...' flickers just before the content shows up and that's annoying. Create an empty file just like this: