Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:36:56+00:00 2026-05-22T20:36:56+00:00

I have a method find_all_media in model abc.rb. Model xyz and abc has relationship,

  • 0
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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:36:57+00:00Added an answer on May 22, 2026 at 8:36 pm

    Seems like your

    def self.find_all_media(media_name)
    
      if self.media_name == self.xyz.media_name
         return media_name
      end
    end 
    

    Method is a class method (self). So, you are trying to access you class method from your class instance

    @abc
    

    You have two options

    1 – Make the method an instance method (by removing the ‘self’)

    2 – Call your method as Abc.find_all_media

    And 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

    :scope (in rails 3.x) (named_scope in rails 2.x)
    

    HTH

    sameera

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a method in a model that looks like this: def self.super_data self.find(:all,
I have this method form a Rails 2.3.4 app: def self.find_all_colored(query, options={}) finder_options =
In my messages_controller I have the following private method: def find_message_or_404(slug) message = user.messages.find_by_slug(slug)
I have the following application_controller method: def current_account @current_account ||= Account.find_by_subdomain(request.subdomain) end Should I
I have a method in a rails 3 model that parses XML with nokogiri.
I'm using Geokit. I have the following in my model: # Distance-based finder method
I have a method that will provide an array of model object. Some of
I have a model that has ratings in it for an post. I want
I have this create method: def create ... grid = Tag.find_by_id(story[:tag_id]) or raise GridNotFoundError
I'm running into a Spring (3.1) mapping conundrum: I have a simple, findAll method:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.