0

A somewhat complex action assembles two set of arrays into a single one.

@packages = (@packageoffers + @availables).sort_by(&:cost).paginate :page => params[:page], :per_page => 20

The view then renders a partial

@packages.each do |package|
  if @packages_m.include?(package)
    @mss = true
    render partial: 'package', collection: @packages
  elsif @availables.include?(package)
     @mss = false
     render partial: 'package', collection: @packages
  else
  end

Said partial then has two conditional block based on @mss (html code stripped):

number_to_currency(markup_price)
if @mss == true
  package.typounit.stars
else
  package.product_category

The error that occurs is occasional

ActionView::Template::Error (undefined method 'product_category' for #<Packageoffer:

Occasional, as the pagination has given a position via triangulation: pages where all results are from one array or the other render. The pages where the results are from both arrays generate the error.

While I can see the behaviour, I fail to comprehend why it functions when the collection comes from the same class.

And thus what is the solution? I see two possibilities:
• Can the partial call the sub array (@packageoffersor @availables)?
• is the boolean @mssa possible culprit?
• pagination can then become an issue as rails can lose track of which collection to count

1 Answer 1

1

I guess a problem is that you render collection https://api.rubyonrails.org/v5.0.7/classes/ActionView/PartialRenderer.html

I hope it can help you

  if @packages_m.include?(package)
    render partial: 'package', locals: { package: package, mss: true }
  elsif @availables.include?(package)
     render partial: 'package', locals: { package: package, mss: false }
  else
  end

  if mss
    package.typounit.stars
  else
    package.product_category
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.