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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:19:55+00:00 2026-06-06T00:19:55+00:00

I am trying to have an element index view displaying the associated projectname (

  • 0

I am trying to have an element index view displaying the associated projectname ( field from db project) and the experimenttype ( field from db experiment ) from has_many_through and belongs to/has many associated models

model element.rb

class Element < ActiveRecord::Base

has_many :project_elements   
has_many :projects, :through => :project_elements

has_many :experiments

attr_accessible :project_ids, :experiment_ids

model project.rb

class Project < ActiveRecord::Base

has_many :project_elements
has_many :elements, :through => :project_elements  

attr_accessible :projectname, :element_ids

model project_element.rb

class ProjectElement < ActiveRecord::Base
belongs_to :project
belongs_to :element
attr_accessible :project_id, :element_id

model experiment.rb

class Experiment < ActiveRecord::Base

belongs_to :element

has_many :welldish_experiments
has_many :welldishs, :through => :welldish_experiments

attr_accessible :exptype, :element_id

elements_controller.rb

  def index
   @elements = Element.all
   respond_to do |format|
     format.html # index.html.erb
     format.json { render json: @elements }
     end

/elements/index.html.erb

 <% @elements.each do |element| %>
  <tr>

    <td><%= element.experiments %></td>
    <td><%= element.projects %></td>    

when i do this , it shows me the whole associated project objet…
same for experiments
and i can’t figure it out how to restrict the display to one single attribute ?

alternatively since the the datas’s been generated using formtastic:

element/_form.html.erb

       <%= semantic_form_for @element do |f| %>    
       <%= f.inputs do %>  
         <%= f.input :projects, :label => "projet associé", :required => true%>
         <%= f.input :experiments, :label => "type d'experience",
     :as => :radio,       :collection => Experiment.all, :required => true %>    
       <% end %>
       <%= f.actions :submit, :cancel %>
       <% end %>

i wonder if there is a quick way from there to generate the index view ( with some render ‘form’ options maybe? )
any help would be appreciated…

  • 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-06T00:19:57+00:00Added an answer on June 6, 2026 at 12:19 am

    the answer was here ( collect method ):
    http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

      <% @elements.each do |element| %>
           <tr>          
           <td><%= element.projects.collect { |a| a.projectname }%></td>
           </tr>
      <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an element from my webpage... I have inserted a control
I'm trying to have this block element to be horizontally aligned in the middle
I am trying to see if an element have a specific CSS attribute. I
I have an element like this: <div id=foo_<?php echo $id;?> class=hidden></div> I'm trying if
I have a DIV element with a background image and I am trying to
I am trying to middle align an element, But I have bumped into this
I am trying to return a computed element with a computed attribute. I have
Here is what I am trying to do: I have a <h1> element, a
I have an MVC3 razor project, which I am trying to build using multiple
For about a week now I have been trying to get a view to

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.