Create a partials path in rails -


im using mailboxer gem allow message sending on app.

i page showing inbox,sent, trash show on single page rather uses having go page see this.

in order have set partial follows:

index.html

<%= render :partial => 'conversations/index', :locals => {:box => @box } %> 

that works fine , see inbox,send , trash links.

however when click on inbox takes me page inbox, send , trash. original conversations/index.html.erb (as opposed _index). reason because _index code follows:

<div class="row">   <div class="col-sm-3">     <ul class="nav nav-pills nav-stacked">       <%= mailbox_section 'inbox', @box %>       <%= mailbox_section 'sent', @box %>       <%= mailbox_section 'trash', @box %>     </ul>   </div>   <div class="col-sm-9">     <ul class="list-group">       <%= render partial: 'conversations/conversation', collection: @conversations %>     </ul>   </div> </div> 

the mailbox_section method defined in helper called conversations_helper.rb follows:

module conversationshelper   def mailbox_section(title, current_box, opts = {})     opts[:class] = opts.fetch(:class, '')     opts[:class] += ' active' if title.downcase == current_box     content_tag :li, link_to(title.capitalize, conversations_path(box: title.downcase)), opts   end end 

it conversations_path taking me conversations/index.html rather letting me stay in partial.

so question is, how change conversations_path stay within partial (removing path doesn't help)

there way of doing (i think) want asynchronously loading rendered partials of boxes (you'll need jquery).

in html,

<div class="row">   <div class="col-sm-3">     <ul id="section-selector" class="nav nav-pills nav-stacked">       <%= mailbox_section 'inbox', @box %>       <%= mailbox_section 'sent', @box %>       <%= mailbox_section 'trash', @box %>     </ul>   </div>   <div class="col-sm-9">     <ul id="conversations" class="list-group">       <%= render partial: 'conversations/conversation', collection: @conversations %>     </ul>   </div> </div>  <script type="text/javascript">   // detect click on mailbox links   ('#section-selector li').click(function() {     // extract box type     var box = $(this).data('box');      // ask server rendered partial of box     $.ajax({       url: "/conversations/" + box,       cache: false,       success: function(html){         // change content of conversations ul new rendered         // partial         $("#conversations").html(html);       }     });   }); </script> 

in controller:

def show   @conversations = conversation.where(box: params[:box]) # or whatever   render partial: 'conversations/conversation', collection: @conversations end 

in helper:

module conversationshelper   def mailbox_section(title, current_box, opts = {})     opts[:class] = opts.fetch(:class, '')     opts[:class] += ' active' if title.downcase == current_box     opts[:data] = {box: title.downcase} # add box type link     content_tag :li, link_to(title.capitalize, '#'), opts   end end 

does seem right ?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -