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 8305271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:04:31+00:00 2026-06-08T18:04:31+00:00

I have a scenario where i am calling a Controller method from the view,that

  • 0

I have a scenario where i am calling a Controller method from the view,that returns an array of pages,which can be either nil or must be having values.i need to iterate that array in a for loop to generate a dynamic list in my view.pls help

  • 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-06-08T18:04:33+00:00Added an answer on June 8, 2026 at 6:04 pm

    Implementing logic in your controllers is generally not a good idea you should move logic into the corresponding model.

    But if you really want to you can use controller variable to reach the actual controller from your view.

    Example:

    <p>
    Now we're printing out the result of the some_method:
    <%= controller.some_method.inspect %>
    </p>
    

    Iterating through the returned value is easy:

    <ul>
    <% controller.some_method.each do |item| -%>
      <li>item.inspect</li>
    <% end -%>
    </ul>
    

    Probably the visibility of the method in your controller is not public, so you may need to use the Object#send method.

    <%= controller.send(:my_protected_method).inspect %>
    

    Update

    To handle the nil reponse, I would create a helper method in the ApplicationHelper class:

    def my_method
      (controller.my_method || [])
    end
    

    And then in the view:

    <% my_method.each do |item| -%>
      <%= item.inspect %>
    <% end %->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario. I'm calling a url which points to a controller method that
How can I get the controller action (method) and controller type that will be
I have this scenario where a webservice method I'm consuming in C# returns a
I have this massive nested loop scenario that is calling the DB and making
Scenario: I have an application that pulls data from a SQL database as well
In my ASP.NET MVC app, I have a view that's calling Html.Action(MyAction, this.Model) -
Hi I have the following scenario. I am calling stored procedures to MySQL 5.x
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario in which I have to run multiple commands one after
I have a scenario where combobox can have same string values. for exa combo

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.