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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:15:03+00:00 2026-06-05T04:15:03+00:00

A ‘product’ has many ‘parallel_products’: class Product < ActiveRecord::Base has_many :parallel_products, :class_name => Product,

  • 0

A ‘product’ has many ‘parallel_products’:

class Product < ActiveRecord::Base
  has_many :parallel_products, :class_name => "Product", :foreign_key => "master_product_id"
end

In the controller I add the ‘parallel_products’ column to the list view:

class ProductsController < ApplicationController
  active_scaffold :product do |config|
    config.list.columns = [ :parallel_products ]
  end
end

This gives me a ActiveScaffold generated link in the list view to view, create and edit parallel products of the selected product.

So far so good.

Now, I want to specify this ‘parallel_products’ link in the helper instead. No changes to the link itself, it should be exactly as the ActiveScaffold generated link. The reason is that I need to add a condition, so that the link is only shown under certain circumstances.

The ActiveScaffold generated link looks like this in the log:

Started GET "/products?assoc_id=6&association=parallel_products&eid=products_6_parallel_products&parent_scaffold=products&adapter=_list_inline_adapter" for 172.16.99.11 at 2012-03-05 09:37:45 +0100
  Processing by ProductsController#index as JS
  Parameters: {"assoc_id"=>"6", "association"=>"parallel_products", "eid"=>"products_6_parallel_products", "parent_scaffold"=>"products", "adapter"=>"_list_inline_adapter"}

My best proposal for the ActiveScaffold has_many relation link in the helper is:

link_to("link text", :controller => "products", :assoc_id => record.id, :association => "parallel_products", :eid => "products_#{record.id}_parallel_products", :parent_scaffold => "products", :adapter => "_list_inline_adapter")

This gives me in the log:

Started GET "/products?adapter=_list_inline_adapter&assoc_id=6&association=parallel_products&eid=products_6_parallel_products&parent_scaffold=products" for 172.16.99.11 at 2012-03-05 09:39:38 +0100
  Processing by ProductsController#index as HTML
  Parameters: {"adapter"=>"_list_inline_adapter", "assoc_id"=>"6", "association"=>"parallel_products", "eid"=>"products_6_parallel_products", "parent_scaffold"=>"products"}

My link does not work, but it seems to be very close. Only difference is that the generated link state ‘ProductsController#index as JS’ and my syntax state ‘ProductsController#index as HTML’.

What is the correct ActiveScaffold syntax for making a ‘has_many’ relation list view link in the helper?

  • 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-05T04:15:04+00:00Added an answer on June 5, 2026 at 4:15 am

    Thanks to Sergio Cambra for helping to solve this.

    This is the syntax for a ‘has_many’ association link if placed in the helper:

    link_to("link text", {:controller => "products", :association => "parallel_products",
      :parent_scaffold => "products", :product_id => record.id}, :class => 'index as_action',
      :id => "as_products-index-parallel_products-#{record.id}-link",
      :remote => true, :data => {:position => :after, :action => 'index'})
    

    To answer the question in full, this is how it can be implemented to exactly replace the autogenerated AS association link:

    def parallel_products_column(record)
      if product.parallel_products.blank?
        link_text = "-"
        css_class = "index as_action empty"
      else
        link_text = product.parallel_products[0...3].map{ |p| p.name }.join(", ")
        if product.parallel_products.length > 3
          link_text += ", &hellip; (#{product.parallel_products.length})"
        end
        css_class = "index as_action"
      end
      link_to(link_text.html_safe, {:controller => "products", :association => "parallel_products",
        :parent_scaffold => "products", :product_id => record.id}, :class => css_class,
        :id => "as_products-index-parallel_products-#{record.id}-link",
        :remote => true, :data => {:position => :after, :action => 'index'})
    end
    

    You will need a small ‘hack’ for the css ’empty’ class, example:

    .active-scaffold a.empty {
      display: block;
      text-align: center;
    }
    

    Note:
    This is for Rails/AS 3.1 or newer.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
The problem with unsigned char. I am reading a PPM image file which has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I was writing code for dragging mechanism which invokes to wait for small period
I downloaded PostgreSQL from the official website and ran the .dmg installer. After that
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to create a RegEx expression that will successfully parse the following

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.