0

Sorry for my noob questions. I use Simple_Form and ERB.HTML for my views. Actually try to implement Cocoon and the guide use SLIM. someone could help me? :)

https://github.com/nathanvda/cocoon

In our projects/_form partial we'd write:

= simple_form_for @project do |f|
  = f.input :name
  = f.input :description
  %h3 Tasks
  #tasks
    = f.simple_fields_for :tasks do |task|
     = render 'task_fields', :f => task
    .links
      = link_to_add_association 'add task', f, :tasks
  = f.submit

In our _task_fields partial we write:

.nested-fields
  = f.input :description
  = f.input :done, :as => :boolean
  = link_to_remove_association "remove task", f
  • Take a look at http://stackoverflow.com/questions/23277482/how-can-i-convert-html-slim-to-html-erb – Damax Feb 16 '15 at 02:24

1 Answers1

0

The code will by like this. In the _form partial:

<%= simple_form_for @project do |f| %>
  <%= f.input :name %>
  <%= f.input :description %>
  <h3>Tasks</h3>
  <%= f.simple_fields_for :tasks do |task| %>
    <%= render 'task_fields', :f => task %>
  <% end %>
  <%= link_to_add_association 'Add Task', f, :tasks %>
  <% f.submit %>
<% end %>

And in the partial _task_fields:

<%= f.input :description %>
<%= f.input :done, :as => :boolean %>
<%= link_to_remove_association "remove task", f %>

Note:

The above example is of Simple Form gem and not of default rails form_for. So install the gem before using this.

And to use cocoon gem do take care of the partial naming i.e., for example _task_fields. If you want to provide any other name then there are options for it given in the gem documentation. Or by default it will search for that name.

Deepesh
  • 6,138
  • 1
  • 24
  • 41