Rails partials:找不到在我的partial中引用新方法的位置

时间:2010-01-17 05:46:14

标签: ruby-on-rails ruby partials

我是Rails的新手,我正在试图弄清楚如何向ActiveView类添加一个方法,以便我可以从partials访问一个新方法。

以下是一些示例代码:

%li
  =link_to "#{h aim_small.description.shorten} #{"(current aim)" if aim_small.description == current_aim.description}", :action => 'show', :id => aim_small
  .options
    =link_to "edit", :controller => 'aims', :action => 'edit', :id => aim_small
    =link_to "remove", :controller => 'aims', :action => 'destroy', :id => aim_small

我希望能够在上面的部分中调用current_aim方法,但是我很难让Ruby识别它的存在。

感谢。

2 个答案:

答案 0 :(得分:1)

第二行中对current_aim的调用不正确,您应将其更改为此

=link_to "#{h aim_small.description.shorten} #{current_aim if aim_small.description == current_aim.description}", :action => 'show', :id => aim_small

答案 1 :(得分:0)

只需将方法'current_aim'放入ApplicationHelper:)