Ruby on Rails link_to_unless_current无效

时间:2014-01-14 01:57:04

标签: 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>)。

2 个答案:

答案 0 :(得分: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)

我会在你的路线文件中做出改变......

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>

我认为这会奏效......