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

  • Home
  • SEARCH
  • 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 3843596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:57:38+00:00 2026-05-19T15:57:38+00:00

I had a controller that was returning all the articles of my website @articles

  • 0

I had a controller that was returning all the articles of my website

 @articles = Article.find(all)

and a partial that used to render the @articles array.

I have changed my controller to :

@articles = User.find(1).topics.map { |t| t.articles }

So I can return some other data as well

After inspection on the Rails Console I found out that the problem is that the output array of collect does not match the Article.find(all)

Output array of find(all)

[#<Article id: 1, user_id: 2, title: "test">]

Output array of collect

[[#<Article id: 1, user_id: 2, title: "test">]] 

When I’m trying to render the parcial i get:

variable:undefined method `model_name' for Array:Class 

My Index

<%= render :partial => @articles%> 

and then the parcial:

<%= link_to_unless_current h(article.title), article %> <%= h(article.body) %>

Does anyone knows how to overcome the problem with the double brackets [[ ]] of the array?

  • 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-19T15:57:39+00:00Added an answer on May 19, 2026 at 3:57 pm

    First, for the first line, I think you have a typo that should be :all instead of all 😀

    t.articles returns you a collection of articles.

    So map {|t| t.articles} gives you a collection of collections of articles (the array of arrays).

    You could try this:

    @articles = User.find(1).topics.map { |t| t.articles }.flatten.uniq
    # uniq if an article could belongs to two or more topics. Otherwise it is not needed.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something like this might had worked <%= Html.RouteLink(, new { controller = Article, action
I had to delete all the rows from a log table that contained about
I have a controller that is being called twice from an ActionLink call. My
I have a very simple MVC site that is returning a 404 not found
I have a view controller that is inside a popover, and I want to
I have a PartialView, on a form that does an ajax post. All my
I have a tab bar controller with different view controllers all using the same
I have a link that when clicked needs to call a controller action with
I had used Server Explorer and related tools for graphical database development with Microsoft
I had a discussion with some colleagues mentioning that there are not too many

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.