Table Relationship Reference Ruby on Rails
I am currently working on a web application where a contractor
(electrician, roofer, plumber) etc can make a proposal online. Pictures,
youtube videos of the project, and a text description will be provided to
the contractor from the customer.
So far I am working on the pictures feature using carrierwave
This is the table of this model in my schema
create_table "project_pictures", force: true do |t|
t.string "name"
t.string "picture"
t.datetime "created_at"
t.datetime "updated_at"
end
Here are my two records in my rails console
ProjectPicture Load (0.4ms) SELECT "project_pictures".* FROM
"project_pictures"
=> #<ActiveRecord::Relation [#<ProjectPicture id: 2, name: "Request for
Siding Quote Customer A", picture: "siding.jpg", created_at: "2013-08-15
16:10:22", updated_at: "2013-08-15 16:47:02">, #<ProjectPicture id: 1,
name: "Request for Siding Quote Customer A", picture:
"sidingrequest.jpg", created_at: "2013-08-14 01:54:27", updated_at:
"2013-08-15 16:47:39">]>
The thing is I am trying to link multiple pictures to one customer. Lets
say the above two pictures belong to one customer and there are two rows
because there are two pictures.
How do I reference that in the table, lets say I have one customer and
thats me "judy" both the record should reference judy's id?
and then eventually in the view, I can draw both pictures out using an
image tag that belong to the customer id 1 - with name = "judy" or just
customer id = 1?
If I am not making things clear please let me know, I am not that familiar
with tables relationships and which relationship will help me the most.
No comments:
Post a Comment