Hi list,
I know a similar question has been posted recently, but I am having
real trouble relating it to my example.
I have managed to create a nested form that allows users to enter
data about Universities and resources on the same page. I want to be able to show corresponding Uni and resource data in my view, but am running in to a few problems.
I'm not sure if this fact impacts, but resources and universities
have their own controllers and models. I simply added a bit of code to my unibersities controller and _form to render the resource and uni fields on the same page.
I have created a foreign key in the 'resource' table, as one
university can have many resources. When trying to display the universities/show.html.erb page I get the following error.
ActiveRecord::StatementInvalid in Universities#show
Showing /home/resource_portal/website/app/views/universities/show.html.erb where line #17 raised:
SQLite3::SQLException: no such column: resources.university_id: SELECT "resources".* FROM "resources" WHERE ("resources".university_id = 7)
Extracted source (around line #17):
14: <b>Country:</b>
15: <%= @university.country %>
16: <b> resources</b>
17: <%= join_resources(@university) %>
18: </p>
19: 20:
`
`
Rails.root: /home/resource_portal/website
I thought the foreign key I added to the 'resource' table would have
created the resources.university_id column, but I guess not.
Do I need to create some sort of new table or column? Apologies but
my DB knowledge is pretty rusty.
For reference here is the method in my helper:
def join_resources(university)
university.resources.map { |r| r.name }.join(", ")
end
end
Any help would be great.
Thanks in advance,
Jen!