Skip to content

Commit

Permalink
Removed the second argument for the nested fields_for block and retri…
Browse files Browse the repository at this point in the history
…eve it from the yielded fields_for.
  • Loading branch information
alloy committed Jan 22, 2009
1 parent c9dca58 commit d142946
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
6 changes: 3 additions & 3 deletions app/helpers/projects_helper.rb
@@ -1,9 +1,9 @@
module ProjectsHelper
def remove_link_unless_new_record(fields, record)
unless record.new_record?
def remove_link_unless_new_record(fields)
unless fields.object.new_record?
out = ''
out << fields.hidden_field(:_delete)
out << link_to_function("remove", "$(this).up('.#{record.class.name.underscore}').hide(); $(this).previous().value = '1'")
out << link_to_function("remove", "$(this).up('.#{fields.object.class.name.underscore}').hide(); $(this).previous().value = '1'")
out
end
end
Expand Down
12 changes: 4 additions & 8 deletions app/views/projects/_form.html.erb
Expand Up @@ -17,16 +17,14 @@
</p>

<div id="tasks">
<!-- Notice that this nested fields_for block not only receives the form builder,
but also the `task' instance for this form builder. -->
<% project_form.fields_for :tasks do |task_form, task| %>
<% project_form.fields_for :tasks do |task_form| %>
<div class="task">
<p>
<%= task_form.label :name, "Task:" %>
<%= task_form.text_field :name %>
<!-- Uses JS to hide this `task' and set a hidden_field with the name
`_delete' to "1" which causes the record to be deleted. -->
<%= remove_link_unless_new_record(task_form, task) %>
<%= remove_link_unless_new_record(task_form) %>
</p>
</div>
<% end %>
Expand All @@ -36,15 +34,13 @@
</p>

<div id="tags">
<!-- Notice that this nested fields_for block not only receives the form builder,
but also the `tag' instance for this form builder. -->
<% project_form.fields_for :tags do |tag_form, tag| %>
<% project_form.fields_for :tags do |tag_form| %>
<div class="tag">
<p>
<%= tag_form.label :name, "Tag:" %>
<%= tag_form.text_field :name %>
<% unless tag.new_record? %>
<% unless tag_form.object.new_record? %>
<!-- For existing records we add a checkbox to be able to delete records. -->
<%= tag_form.label :_delete, "Remove:" %>
<%= tag_form.check_box :_delete %>
Expand Down

0 comments on commit d142946

Please sign in to comment.