Updated README with standard Rails forms example

This commit is contained in:
Joel Cogen 2012-07-31 14:36:58 +03:00
parent c0fd78fea2
commit 0cd06df780
1 changed files with 38 additions and 3 deletions

View File

@ -26,7 +26,7 @@ Inside your `Gemfile` add the following:
gem "cocoon" gem "cocoon"
```` ````
### Rails 3.1 ### Rails 3.1+
Add the following to `application.js` so it compiles to the Add the following to `application.js` so it compiles to the
asset_pipeline asset_pipeline
@ -35,7 +35,7 @@ asset_pipeline
//= require cocoon //= require cocoon
```` ````
### Rails 3.x ### Rails 3.0.x
If you are using Rails 3.0.x, you need to run the installation task (since rails 3.1 this is no longer needed): If you are using Rails 3.0.x, you need to run the installation task (since rails 3.1 this is no longer needed):
@ -153,7 +153,42 @@ There is an example project on github implementing it called [cocoon_simple_form
### Using standard rails forms ### Using standard rails forms
I will provide a full example (and a sample project) later. Inside our `projects/_form` partial we then write:
````haml
- form_for @project do |f|
.field
= f.label :name
%br
= f.text_field :name
.field
= f.label :description
%br
= f.text_field :description
%h3 Tasks
#tasks
= f.fields_for :tasks do |task|
= render 'task_fields', :f => task
.links
= link_to_add_association 'add task', f, :tasks
= f.submit
````
and inside the `_task_fields` partial we write:
````haml
.nested-fields
.field
= f.label :description
%br
= f.text_field :description
.field
= f.check_box :done
= f.label :done
= link_to_remove_association "remove task", f
````
I will provide a sample project later.
## How it works ## How it works