2014-04-23 39 views
0

我在鐵軌下面的圖像標記APP-導軌:含顯示工具提示鏈接

<%= link_to image_tag("../../qn/ads.svg"),{:controller => 'cp_details',:action => 'index', :id => empid, :cp => @cmpny.id }, :title=>"company", :class => 'butn' %> 
<%= link_to image_tag("../../qn/users.svg"),{:controller => 'groups',:action => 'index', :id => empid, :cp => @cmpny.id }, :title=>"groups", :class => 'butn' %> 
<%= link_to image_tag("../../qn/dp.svg"),{:controller=>'dep',:action => 'index', :id => empid, :cp => @cmpny.id,:type=>'dp' }, :title=>"dept", :class => 'butn' %>` 

現在我想實現的工具提示彈出,在它上面的鏈接(點擊或hoverover時)。任何人都可以幫助我實現工具提示,其中包含公司,團體,部門三個鏈接的工具提示框?我所提及的且嘗試了以下事項

https://gist.github.com/davidjsevans/5617391

Bootstrap Tooltip in Ruby on Rails

Using Tooltips with link_to (Ruby on Rails 3.2.3)

http://archive.railsforum.com/viewtopic.php?id=28485

但我覺得我不知道該如何在我的應用程序實現這些。我正在嘗試application.js內的js和jquery以及employ/index.html中的link_to代碼。我試圖實現它在的link_to聲明是這樣的一個:

<%= link_to image_tag("../../qn/ads.svg"),{:controller => 'cp_details',:action => 'index', :id => empid, :cid => @cmpny.id }, :title=>"company", :class => 'butn tag-tooltip', tag, :data => {:toggle=>"tooltip"},'data-original-title' => "Hello",'data-placement' => 'right'%>` 

的Javascript:

$(document).on("ready page:change", function() { 
    $('.tag-tooltip').tooltip(); 
}); 

然後我想這太:

<div id="tooltipelement"> 
    <a href="#" onclick="javascript:window.location = '/cp_details/index/<%=empid%>?cp=<%[email protected]%>'">Company</a> 
</div> 

CSS:

.tooltipelement{ 
    width: 20px; 
    height: 20px; 
    background: red; 
} 

.tooltipelement a { 
    display: none; 
    padding-left: 30px; 
} 

.tooltipelement:hover a { 
    display: block; 
    background: green; 
} 

但所有這些都沒有效果因爲我不知道如何正確實施它們。我希望所有三個鏈接出現在工具提示彈出框內。誰能幫幫我嗎?提前致謝。

+0

https://github.com/brandonhilkert/bootstrap-tooltip-rails – SSR

回答

1

我想你會更好使用bootstrap popover plugin - 提示主要爲鏈接的title屬性轉換爲JavaScript的電動工具提示


你的問題是你想包括鏈接等進入你的工具提示。工具提示文字清晰,並且支持popovers HTML,你應該能夠以包括的他們

每一個環節根據所提供的bootstrap website的信息,你最好這樣做:

<%= link_to "link", path(), class: class="butn", data: { toggle: "popover", content: popover_links } %> 

#app/helpers/application_helper.rb 
def popover_links 
    link_to("something", something_path) + 
    link_to("something", something_path) 
end 

參考:What is the best way to return multiple tags from a Rails Helper?

+1

抱歉打擾你,我在軌初學者。 'def popover_links link_to(「company」,'/cp_details/index/[email protected]')+ link_to(「groups」,'/groups/index/[email protected] cmpny.id') end <%= link_to「link」,path(),class:「butn」,data:{toggle:「popover」,content:popover_links}%> 這裏應該給我什麼路徑()?以及如何將empid和@ cmpny.id的值傳遞給方法popover_links?我想我真的很困惑。 – liya

+1

'path()'是你想要使用的URL。對你來說,它應該是'{:controller =>'cp_details',:action =>'index',:id => empid,:cp => @ cmpny.id}':) –

+0

你需要閱讀[的link_to](HTTP://api.rubyonrails。org/classes/ActionView/Helpers/UrlHelper.html) - 它將幫助你看到它應該如何工作:) –