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:
........
<script>
function addDiv(frm) {
document.getElementById(''readroot'').style.display=''block''
var newFields =
document.getElementById(''readroot'').cloneNode(true);
document.getElementById(''readroot'').style.display=''none''
newFields.id = '''';
newFields.style.display = ''block'';
var newField = newFields.childNodes;
var insertHere = document.getElementById(''container'');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
</script>
......
if(@contact.notas)
@contact.notas.each do |nota| %>
<textarea cols="40" id="contact_nota"
name="contact[nota]" rows="3" >
<%= nota.nota %>
</textarea> <br>
<% end end %>
<div id="readroot" style="display:none;">
<p><textarea cols="40" id="contact_nota"
name="contact[nota]" rows="3"
></textarea></p>
</div>
<div id="container"></div>
<input type="button" value="Add a note"
onclick="addDiv();" /><br /><br
/>
....
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---