Hi all
I’m a ruby beginner so I hope to get some help on this forum. I have
seen that there are allready some posts on this subject, but I can’t
seem to get them to work on my test project.
To give some info. I have a table Contacts. This table contains some
information on a person like name, address, etc. The table notas
contains a simple id, an contact_id and a field for the nota itself.
In my Nota model I say the following thing: belongs_to : contact
In my Contact model I say: has_many :notas
I have generated my new/edit contact form through the ruby script
scaffold. Offcours it only contains all the contact fields. So I added
the following:
…
…
if(@contact.notas)
@contact.notas.each do |nota| %>
<%= nota.nota %>
<% end end %>
....
For test reasons I allready added some notas in the DB with phpMyAdmin.
And so far, so good, alle the notas for a certain contact are displayed.
But when I add or edit them through the application, I get the following
error:
undefined method `nota=’ for #Contact:0x474d69c
This is probably due to the fact that the contact model doesn’t has any
fields called nota. So I should tell RoR to add/edit those fields in the
notas table (most likely in the update methode of the Contact
controller). But as I said, I’m only a ruby beginner, and I would realy
like to know how you can accomplish this in ruby on rails.
The reason for this is that I have a similar tool (its bigger and has
more functionality to it) written in PHP, but after reading up on ruby
on rails I believe that ruby is the way to the futur. I have allready
searched through some books on ruby (on rails) that I bought, but I
can’t seem to find a familiar case study on it.
So hopefully there is someone who can point me to the right direction.
Thank you in advance