The simplist would be something like this...
= Migrations
create_table :items do |t|
t.column :name, :string
t.column :description, :text
end
create_table :notes do |t|
t.column :item_id, :int
t.column :body, :text
end
= Models
class Item < ActiveRecord::Base
has_many :notes
end
class Note < ActiveRecord::Base
belongs_to :note
end
= Controllers
have a ItemController and NoteController.
After you create an item then create the notes for that item in a seperate form.
In the note form have a hidden field that contains the primary key of
the related item
<input type="hidden" name="note[item_id]"
value="123" />
<textarea name="note[body]"></textarea>
Use form_for or remote_form_for to generate the above HTML.
Before creating the note validate that the submited item_id coresponds
to and item acutally in the database.
Peter
On 9/5/06, Henrik Ekenberg
<henrik.ekenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I want to create multi notes for one item. How can I do so in Rails.
>
> Steps I want.
> 1- create a new item
> 2- write in the edit screen name,desc,....
> 3- Add some notes to this item ( from 1 to 20 notes)
> 4- Save the new item.
>
> Any good link or nice document ?
>
> Thanks
> Henrik E
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs
-~----------~----~----~----~------~----~------~--~---