Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Padilla
committed
Apr 26, 2011
1 parent
f3dbd38
commit 85f7945
Showing
8 changed files
with
67 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
require 'action_view' | ||
require 'ajax-nested-fields/helpers' | ||
|
||
# module NestedFields | ||
# def self.included(base) | ||
# base.extend(ClassMethods) | ||
# end | ||
# end | ||
|
||
# class ActionView::Base | ||
# include NestedFields | ||
# end | ||
ActionView::Base.send :include, AjaxNestedFields::Helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module AjaxNestedFields | ||
module Helpers | ||
def just_a_helper | ||
"success" | ||
end | ||
|
||
def link_to_remove_fields(name, f, container) | ||
f.hidden_field(:_destroy) + link_to_function(name, "remove_fields(this, '#{container}')") | ||
end | ||
|
||
def link_to_new_child(f, association) | ||
object = f.object.class.reflect_on_association(association.to_sym).klass.new | ||
|
||
fields = f.fields_for(association, object, :child_index => "new_#{association.singularize}") do |builder| | ||
render("#{association.singularize}_fields", :f => builder) | ||
end | ||
|
||
link_to_function "Add #{association}", h("add_child_field('#{association}', 'new_#{association.singularize}', \"#{escape_javascript(fields)}\")") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'test_helper' | ||
require 'action_view/template/handlers/erb' | ||
|
||
class Movie | ||
extend ActiveModel::Naming | ||
include ActiveModel::Conversion | ||
|
||
def persisted? | ||
false | ||
end | ||
|
||
def _destroy | ||
|
||
end | ||
end | ||
|
||
class HelpersTest < ActionView::TestCase | ||
include AjaxNestedFields::Helpers | ||
|
||
def test_link_to_remove_fields | ||
movie = Movie.new | ||
result = form_for movie do |f| | ||
link_to_remove_fields('movie_name', f, 'movies') | ||
end | ||
|
||
assert_match result, %r{onclick="remove_fields\(this, 'movies'\); return false;"} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.