Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

How do I display related or similar Ads by currency on the Ad show page?

Rails • Asked by Charlie Kay
Hi Chris I need your help on this please.  I'm trying to display related Ads on the Ad show page by currency. But somehow  my script displays the same Ad in multiples of related Ads and not showing the actual related Ads. 

belongs_to :currency

has_many :ads

Ads Controller
def show
@related_ads = Ad.where.not(currency_id: @ad.currency_id)

<% @related_ads.each do |ad| %>
<%= %>
<% end %>


What is in the `@ad` variable you refer to in your show action?

Thanks a lot Jack! It should be 'ad' in the show page instead of '@ad' and ads_controller:
def show
@related_ads = Ad.where(currency_id: @ad.currency_id)
This works fine.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 29,763+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.