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 -
Listing activities
<%= title.name %> | |||
---|---|---|---|
Name | Action | ||
<%=h activity.name %> | <%= link_to 'Show', activity %> | <%= link_to 'Edit', edit_activity_path(activity) %> | <%= link_to 'Destroy', activity, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to "New Activity", new_activity_path %> |
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