0

我对 Rails 还很陌生,正在尝试弄清楚如何向 ActiveView 类添加一个方法,以便我可以从部分访问一个新方法。

这是一些示例代码:

%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 识别它的存在。

谢谢。

4

2 回答 2

1

第二行的调用current_aim不正确,你应该把它改成这个

=link_to "#{h aim_small.description.shorten} #{current_aim if aim_small.description == current_aim.description}", :action => 'show', :id => aim_small
于 2010-01-17T08:45:59.650 回答
0

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

于 2010-01-17T06:17:56.417 回答