Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Render partial inside Twitter Bootstrap popover

I want to use a Twitter Bootstrap popover to display a user avatar and email address, with the possibility of adding in more details at a later date.

I am having an issue getting the partial to render inside the content field of the link. The view code is below (in HAML).

%span.comment-username
    =link_to comment.user_name, "#", "title" => comment.user_name,
      "data-content" => "=render 'users/name_popover'", 
      class: "comment-user-name"

Currently, this will only produce the content code as a string.

Is there a way to do this so the partial will be inserted instead of the code as a string?

like image 595
jmc Avatar asked Sep 16 '12 02:09

jmc


2 Answers

You want rails to actually evaluate the content of the string and not just show the string. The easiest way to do that would be:

%span.comment-username
  =link_to comment.user_name, "#", "title" => comment.user_name,
    "data-content" => "#{render 'users/name_popover'}", 
      class: "comment-user-name"

That should pass the render statement to rails and render your partial as expected.

like image 164
jrc Avatar answered Oct 27 '22 00:10

jrc


Thanks for the answer jrc - it helped me find a solution.

My solution might be useful for other non HAML people like me:

`<%= link_to('Service History' , '#', :class => "popover-history", :rel => "popover", :"data-placement" => "bottom", :title => "Service History", :"data-content" => "#{render 'services/service_history'}") %>`

with

`$(function () {
$('.popover-history').popover({ html : true });
});`
like image 24
jared Avatar answered Oct 27 '22 01:10

jared