Saturday, July 21, 2012

[Rails] Find Company Name not ID

I am at a loss why this is not working.....I just want to show the
company name if the contact instead of the .id. Any assistance would be
grateful.

class Contact < ActiveRecord::Base
belongs_to :company

class ContactsController < ApplicationController
def index
@contacts = Contact.all

@company = Company.find(@contact.company_id)

and in the view:

<%= @company.company_name%>

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate