2014-01-14 60 views
0

我希望使用link_to_unless_current來插入一些鏈接(與您一樣)。 我顯示的代碼是:Ruby on Rails link_to_unless_current不起作用

<div> 
    <div><% link_to_unless_current 'Right Eye', {:action => 'graphnew', :params => {:right => true}} %></div> 
    <div><% link_to_unless_current 'Left Eye', {:action => 'graphnew', :params => {:left => true}} %></div> 
    <div><% link_to_unless_current 'Both Eyes', {:action => 'graphnew'} %></div> 
    <div><% link_to_unless_current 'Show Natural History', {:action => 'graphnew', :params => {:nh => true}} %></div> 
    </div> 

控制器是 「PatientsController」,動作是 「graphnew」,路線是:

/patients/:id/graphnew {:controller=>"patients", :action=>"graphnew"} 

和它所有的渲染都是空白的div(<div></div>) 。

回答

0

問題出在<%,它不會在視圖中呈現ruby代碼。如果我們做<%=,你應該看到它們。

<div> 
    <div><%= link_to_unless_current 'Right Eye', {:action => 'graphnew', :params => {:right => true}} %></div> 
    <div><%= link_to_unless_current 'Left Eye', {:action => 'graphnew', :params => {:left => true}} %></div> 
    <div><%= link_to_unless_current 'Both Eyes', {:action => 'graphnew'} %></div> 
    <div><%= link_to_unless_current 'Show Natural History', {:action => 'graphnew', :params => {:nh => true}} %></div> 
    </div> 
+1

唉!謝謝斯蒂芬! –

+0

沒問題,歡呼! :) –

0

我會想辦法讓你的路線文件中的變化...

get '/graphnew', to: 'patients#graphnew' 

那麼你的路徑將是...

<div> 
    <div><%= link_to_unless_current 'Right Eye', graphnew_path(right: true) %></div> 
    <div><%= link_to_unless_current 'Left Eye', graphnew_path(left: true) %></div> 
    <div><%= link_to_unless_current 'Both Eyes', graphnew_path %></div> 
    <div><%= link_to_unless_current 'Show Natural History', graphnew_path(nh: true) %></div> 
</div> 

我認爲這會工作...

相關問題