On Wednesday, July 20, 2011 4:52:50 PM UTC-6, Jen wrote:>
> 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.
>
Did you run: rake db:migrate (after creating the migration that creates this
column)?
I''m assuming you added the foreign key by creating a new migration that
adds
a column to resources (as opposed to modifying existing migration files).
>
> Do I need to create some sort of new table or column? Apologies but my DB
> knowledge is pretty rusty.
>
You''re on the right track. You just haven''t succeeded in
creating the
foreign key column in your database. Either your migration is broken (it
creates a column w/a wrong name), or wasn''t run (you didnt''
run rake
db:migrate) or is in the wrong place (you edited an existing migration so
that even though you ran rake db:migrate, nothing happened).
>
> For reference here is the method in my helper:
>
> def join_resources(university)
> university.resources.map { |r| r.name }.join(", ")
> end
> end
>
>
This is fine.
> Any help would be great.
>
> Thanks in advance,
> Jen!
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/AcDGg2e4L8wJ.
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.