block is aware of tag that uses it
Oleg
committed Sep 27, 2011
commit 27d913e684c450dfab263574157131b690945a6d
Showing 5
changed files with
19 additions
and 5 deletions
app/models/cms/block.rb
+6
-0
| @@ | @@ -18,6 +18,12 @@ class Cms::Block < ActiveRecord::Base |
| :presence => true, | |
| :uniqueness => { :scope => :page_id } | |
| + | # -- Instance Methods ----------------------------------------------------- |
| + | # Tag object that is using this block |
| + | def tag |
| + | page.tags(true).detect{|t| t.is_cms_block? && t.label == label} |
| + | end |
| + | |
| protected | |
| def prepare_files | |
app/models/cms/page.rb
+1
-2
| @@ | @@ -95,8 +95,7 @@ class Cms::Page < ActiveRecord::Base |
| # Processing content will return rendered content and will populate | |
| # self.cms_tags with instances of CmsTag | |
| def content(force_reload = false) | |
| - | @content = read_attribute(:content) |
| - | @content = nil if force_reload |
| + | @content = force_reload ? nil : read_attribute(:content) |
| @content ||= begin | |
| self.tags = [] # resetting | |
| if layout | |
app/views/cms_admin/files/_page_form.html.erb
+3
-0
| @@ | @@ -0,0 +1,3 @@ |
| + | <% block ||= page_form %> |
| + | |
| + | <%= debug block.files %> |
| \ No newline at end of file | |
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb
+3
-3
| @@ | @@ -73,7 +73,8 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder |
| options[:field] || | |
| case method = options[:content_field_method] | |
| when :file_field_tag | |
| - | @template.send(method, 'page[blocks_attributes][][content]', :id => nil, :class => field_css_class) |
| + | @template.send(method, 'page[blocks_attributes][][content]', :id => nil, :class => field_css_class) + |
| + | @template.render(:partial => 'cms_admin/files/page_form', :object => tag.block) |
| else | |
| @template.send(method, 'page[blocks_attributes][][content]', tag.content, :id => nil, :class => field_css_class) | |
| end | |
| @@ | @@ -118,8 +119,7 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder |
| end | |
| def page_file(tag) | |
| - | default_tag_field(tag, :content_field_method => :file_field_tag) + |
| - | "FILES: #{tag.block.files.to_yaml}" |
| + | default_tag_field(tag, :content_field_method => :file_field_tag) |
| end | |
| def collection(tag) | |
test/unit/models/block_test.rb
+6
-0
| @@ | @@ -8,6 +8,12 @@ class CmsBlockTest < ActiveSupport::TestCase |
| end | |
| end | |
| + | def test_tag |
| + | block = cms_blocks(:default_page_text) |
| + | assert block.page.tags(true).collect(&:identifier).member?('page_text_default_page_text') |
| + | assert_equal 'page_text_default_page_text', block.tag.identifier |
| + | end |
| + | |
| def test_new_via_page_nested_attributes | |
| assert_difference ['Cms::Page.count', 'Cms::Block.count'] do | |
| page = Cms::Page.create!( | |