开发者

Rails partials: Trouble finding where to put reference to new method in my partial

开发者 https://www.devze.com 2022-12-16 11:18 出处:网络
I\'m fairly new to Rails and am trying to figure out how to add a method to the ActiveView class so I can then access a new method from the partials.

I'm fairly new to Rails and am trying to figure out how to add a method to the ActiveView class so I can then access a new method from the partials.

Here's some sample code:

%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

I want to be able to call the current_aim method in the above partial, but am having trouble getting Ruby to recognize its existance.

Thanks.


The call to current_aim in de second line is incorrect, you should change it to this

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


Just put the method 'current_aim' into the ApplicationHelper :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号