ruby - Calling a method in the view controller Rails -
to generalize problem, using api returns iterable object. within id each object. controller looks this:
class searchcontroller < applicationcontroller def index @search = api.find(params[:query]) end end
my view this:
<% @search.each |thing| %> <h2><%= thing.attr2 if thing.attr1 %></h2> <%= api.list(thing.attr2) %> <% end %>
i have tried adding method
class searchcontroller < applicationcontroller def index @search = api.find(params[:query]) def getlist(attr2) api.list(thing.attr2) end end end
and adding index , self before definition (ex: self.getlist(attr2)) , calling in variations in view:
<%= getlist(thing.attr2) %>
i wondering going wrong here. have additionally tried add in helper_method line read in few docs not recognize it. also, correct way go style-wise? having hard time finding references makes me think isn't standard practice.
the method trying make helper method, , therefore, needs go in helper method controller.
Comments
Post a Comment