0

I have two tables which are following

contacts table
id
email
name
company
phone

and

signups table
id
contact_id
code
details

And I have two models contacts and signups and have same controllers as well.

What I want here is to get all data from contacts table where contacts table id = signups table contact_id.

How can I do this in ruby on rails?

Update

Here are my models which are empty for now

class Usercontacts < ActiveRecord::Base
#has_one :signups
#has_one :receiver, :class_name => "Signups"
end

HEre is second model

class Signups < ActiveRecord::Base
 attr_accessible :contact_id, :code, :event_id, :details

 #belongs_to :usercontacts
 #belongs_to :receiver, :class_name => "Usercontacts"
end

Now I am doing something like this my signups controller

class SignupsController < ApplicationController
layout 'admin_layout'

def signups
    #@signups = Contact.joins('LEFT OUTER JOIN signups ON contacts.id = signups.contact_id')
            @contacts = Contact.joins(:sign)
end
end

but this gets all the data from contacts table. but I want to get only that data which is whose id is present in signups table.

3
  • 6
    guides.rubyonrails.org/association_basics.html, will be a good starting point. Commented Jul 17, 2012 at 7:54
  • 1
    And this too: guides.rubyonrails.org/… Commented Jul 17, 2012 at 8:04
  • 1
    What do your models look like? What have you tried? You have to show some effort and not expect people to write your code for you. Commented Jul 17, 2012 at 8:06

1 Answer 1

5

you are not following rails conventions

Usercontacts should be UserContact with corresponding table name user_contacts(or Contact if you already have contacts table)

Signups should be Signup with corresponding table name signups

relation declarations follow same conventions - belongs_to :singular_name, has_many :plural_name

if you start following conventions all your problems will go away

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.