I have a method find_all_media in model abc.rb. Model xyz and abc has relationship,
abc :has_many xyzs and
xyz :belongs_to abc
# abc.rb
method is in abc model
def self.find_all_media(media_name)
if self.media_name == self.xyz.media_name
return media_name
end
end
### view file
<% @abc.xyzs.each do |xyz| %>
<tr>
<td><%=h xyz.media_name %></td>
<td><%=h xyz.type %></td>
<td>I want to call method find all_media here ?? </td>
</tr>
I tried but not working, any
I have a method find_all_media in model abc.rb. Model xyz and abc has relationship,
Share
Seems like your
Method is a class method (self). So, you are trying to access you class method from your class instance
You have two options
1 – Make the method an instance method (by removing the ‘self’)
2 – Call your method as
Abc.find_all_mediaAnd just as a best practice,
Do not call models directly from your views, Do it through the controller, or helper
and if your ‘find_all_media’ method is someting to do with database query consider
HTH
sameera