Rails nested layouts - possible to use turbolinks 3 replace partial? -


after learning react-router , ember routing, appreciate idea of nested ui.

trying figure out way push partials divs in 'native' rails , stumbled on simple way of editing in place.

plans/index.html.erb

<% @posts.each |post| %>   <div id="content">     <a onclick="turbolinks.visit('/posts/8/edit', {change: 'content'})" >edit</a>   </div> <% end %> 

plans/edit.html.erb

<div id="content">   <%= form_for @post |form| %>     <%= form.text_field :name %>   <% end %> </div> 

since both files have id="content" correctly puts edit.html.erb content index file in place while maintaining rest of page state.

i way feels, nicer creating remote request, adding controller action, creating new js.erb file, , forcing dom update jquery. super handy making nested tabbed content or master/detail pages simple html.

however code above, how access post id in turbolinks.visit call? hard coded id know exists see if , working. can't figure out how put post id nested string.

you pass post id via string interpolation. try following code:

<% @posts.each |post| %>   <div id="content">     <a onclick="turbolinks.visit("/posts/#{post.id}/edit", {change: 'content'})" >edit</a>   </div> <% end %> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -