Brian Corrigan
2006-Mar-09 15:45 UTC
[Rails] Re: Displaying related tables in forms.. probably an easy qu
Steve - That was the issue.. It seems obvious now, but I needed to reference Property.PropertType.name instead of property.propertytype.name Thanks!! Brian -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Steve Koppelman Sent: Wednesday, March 08, 2006 5:00 PM To: rails@lists.rubyonrails.org Subject: [Rails] Re: Displaying related tables in forms.. probably an easy qu The fact that you named property_type the way you did with an underscore makes it especially important that you understand how Rails deals with names. I''m not 100% sure, but try referencing property.property_type, with the underscore. Rails will know it as PropertyType and property_type depending on the context, but not as propertytype. Brian Corrigan wrote:> Hey All, > > I have two tables.. One belongs to another. Why can''t I reference > table1.table2.attribute? > > Specifically, using scaffolding: > property.rb - > has_one :PropertyType > > property_type.rb - > has_many :Properties > > property_controller - > def list > @property_pages, @properties = paginate :properties, :per_page => 10 > end > > list.html: > 1. <% for property in @properties %> > 2. <tr> > 3. <% for column in Property.content_columns %> > 4. <td> > 5. <%=h property.send(column.name) %> > 6. </td> > 7. <% end %> > 8. <td><%=h property.propertytype.name %></td> > 9. <% end %> > > Two questions: > 1) I get an error stating that I am trying to reference thepropertytype> method on line #8. I thought I was doing this right, I''m using the > local variable (not the instance variable which is an array of objects > in this case). > 2) Am I doing my has_one and belongs_to statements right? Some > documentation seems to say that you only need to use has_one and you > don''t need belongs to? I thought you always needed them as a pair? > > - Brian-- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Reasonably Related Threads
- Displaying related tables in forms.. probably an easy question!
- Parsing a SQL file directly intoactiverecord::executemethod - Not a vamp I swear
- Efficiently convert this SQL statement to ActiveRecord loop
- Parsing a SQL file directly into activerecord::executemethod - Not a vamp I swear
- How to populate form dropdown with 2nd item of model