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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:57:36+00:00 2026-06-01T17:57:36+00:00

For about a week now I have been trying to get a view to

  • 0

For about a week now I have been trying to get a view to render. I have an application that needs to be able to export collections so I decided to use a line partial that renders as a .txt and .csv in the web browser. So far so good in terms of getting the entire collection to render (line by line). However, I am having trouble getting certain collection objects (in this case products) to duplicate themselves based on a certain attribute (size element).

The code below is kind of where I am stuck at now

Controller

class PexportController < ApplicationController
  layout 'csv'

  def index
  end

  def show
    @feed_template = params[:id]
    @products = Product.find :all
    @products.each do |product|
      unless product.size.nil? || product.size.empty? || product.size.kind_of?(Fixnum)
        @products << new_products_for(product)
      end
    end

    respond_to do |format|
      format.html
      format.text
    end
  end

  private

  def new_products_for(product = {})
    products = Array.new
    product.size.each do |p|
      products << Product.new(p.attributes)
    end
    products
  end
end

View

<%= render partial: 'pexport/p', collection: @products %>

Partial

<%= p.sku %>  <%= p.name %> <%= p.price %> ......

I basically just need to get the controller method to work. The attribute :size that I am using for the line duplicator is simply an array like so [1,2,3]. And I would like products that contain this size attribute to duplicate themselves based on the number of sizes in their size array. I am not even sure if I am going about it the right away but it has gotten to that point where I am going in circles so I figured I would post it.

  • 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-01T17:57:38+00:00Added an answer on June 1, 2026 at 5:57 pm

    Alternative answer: is there some reason you need to duplicate the entire object in the controller? You could simplify things by just doing something like this in your view:

    <% if p.size.is_a?(Array) %>
      <% p.size.each do |s| %>
        <%= p.sku %>  <%= p.name %> <%= p.price %> <%= s %>
      <% end %>
    <% else %>
      <%= p.sku %>  <%= p.name %> <%= p.price %> <%= p.size %>
    <% end %>
    

    Or something to that effect.

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

Sidebar

Related Questions

I've been learning wpf for about a week now.. and i have a basic
I have been trying to get up to speed on Named Pipes this week.
I have been battling a problem now for about a week and it's really
For a week now I've been trying to get my mono configuration running with
I've been trying to solve this problem for about a week now. I posted
Platform: C# 2.0 Using: Castle.DynamicProxy2 I have been struggling for about a week now
I have been searching for about a week now and found such pure AS3
I have been playing around with the twisted framework for about a week now(more
We have an ASP.NET 3.5 application that has been in production for over a
I have been using Issue Tracking system for a week . Right now ,

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.