Hello all,
I about to pull my hair out.
I have two models "Activities" and "Activity_types"
Activities
----------
id
name
activity_type_id
Activity_types
--------------
id
name
- Associations -
class Activity < ActiveRecord::Base
  has_many :activity_types
end
class ActivityType < ActiveRecord::Base
  belongs_to :activity
end
- activities_controller -
def index
    @activities = Activity.find(:all, :joins => :activity_types)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @activities }
    end
  end
- index.html.erb -
<h1>Listing activities</h1>
<table class="activities">
  <% @activityTypeTitle.each do |title| %>
  <tr><th><h3><%= title.name
%></h3></th></tr>
  <tr>
    <th>Name</th>
  <th colspan="3">Action</th>
  </tr>
<% @budgetActivities.each do |activity| %>
  <tr>
    <td><%=h activity.name %></td>
    <td><%= link_to ''Show'', activity %></td>
    <td><%= link_to ''Edit'',
edit_activity_path(activity) %></td>
    <td><%= link_to ''Destroy'', activity, :confirm
=> ''Are you sure?'',
:method => :delete %></td>
  </tr>
<% end %>
  <tr><td><%= link_to "New Activity", new_activity_path
%></td></tr>
<% end %>
</table>
<br />
All I''m trying to do is list the ''types'' as a header
of a table with the
activities in rows.
When I try to do the join, I get...
"SQLite3::SQLException: no such column: activity_types.activity_id:
SELECT "activities".* FROM "activities"   INNER JOIN
"activity_types" ON
activity_types.activity_id = activities.id"
Thank you for any help with this.
JohnM
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
You''ve got your has_many and belongs_to backwards. On Thu, Feb 11, 2010 at 11:34, John Mcleod <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hello all, > > I about to pull my hair out. > > I have two models "Activities" and "Activity_types" > > Activities > ---------- > id > name > activity_type_id > > Activity_types > -------------- > id > name > > - Associations - > > class Activity < ActiveRecord::Base > has_many :activity_types > end > > class ActivityType < ActiveRecord::Base > belongs_to :activity > end > > - activities_controller - > > def index > @activities = Activity.find(:all, :joins => :activity_types) > > respond_to do |format| > format.html # index.html.erb > format.xml { render :xml => @activities } > end > end > > - index.html.erb - > > <h1>Listing activities</h1> > > <table class="activities"> > <% @activityTypeTitle.each do |title| %> > <tr><th><h3><%= title.name %></h3></th></tr> > <tr> > <th>Name</th> > <th colspan="3">Action</th> > </tr> > > <% @budgetActivities.each do |activity| %> > <tr> > <td><%=h activity.name %></td> > <td><%= link_to ''Show'', activity %></td> > <td><%= link_to ''Edit'', edit_activity_path(activity) %></td> > <td><%= link_to ''Destroy'', activity, :confirm => ''Are you sure?'', > :method => :delete %></td> > </tr> > <% end %> > <tr><td><%= link_to "New Activity", new_activity_path %></td></tr> > <% end %> > </table> > <br /> > > All I''m trying to do is list the ''types'' as a header of a table with the > activities in rows. > > When I try to do the join, I get... > > "SQLite3::SQLException: no such column: activity_types.activity_id: > SELECT "activities".* FROM "activities" INNER JOIN "activity_types" ON > activity_types.activity_id = activities.id" > > Thank you for any help with this. > > JohnM > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks Mat, That did it. I checked with debug and how do I get the type Name? John -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Feb 11, 2010 at 11:56, John Mcleod <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Thanks Mat, > That did it. > I checked with debug and how do I get the type Name? > > John > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >You should probably familiarize yourself with this: http://guides.rubyonrails.org/association_basics.html -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
if I include ":include => :activity_type", then I get the name.
debug @activities
- !ruby/object:Activity
  activity_type: &id001 !ruby/object:ActivityType
    attributes:
      name: Budgeting
      created_at: 2010-01-25 14:38:25
      updated_at: 2010-01-25 14:38:25
      id: "1"
    attributes_cache: {}
  attributes:
    name: Study Mapping & Budget Workup
    created_at: 2010-01-25 14:44:51
    updated_at: 2010-01-25 14:44:51
    activity_type_id: "1"
    id: "1"
  attributes_cache: {}
How to display "name"?
John
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for help. John -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
activity.activitytypes.name On Feb 11, 11:10 am, John Mcleod <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> if I include ":include => :activity_type", then I get the name. > > debug @activities > > - !ruby/object:Activity > activity_type: &id001 !ruby/object:ActivityType > attributes: > name: Budgeting > created_at: 2010-01-25 14:38:25 > updated_at: 2010-01-25 14:38:25 > id: "1" > attributes_cache: {} > > attributes: > name: Study Mapping & Budget Workup > created_at: 2010-01-25 14:44:51 > updated_at: 2010-01-25 14:44:51 > activity_type_id: "1" > id: "1" > attributes_cache: {} > > How to display "name"? > > John > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.