wip

Oleg committed Sep 27, 2011
commit fae8f0ac00c80f674bfbe7914c477ed76edb4d33
Showing 5 changed files with 30 additions and 3 deletions
app/models/cms/block.rb +8 -0
@@ @@ -7,9 +7,17 @@ class Cms::Block < ActiveRecord::Base
# -- Relationships --------------------------------------------------------
belongs_to :page
+ before_save :save_file
+
# -- Validations ----------------------------------------------------------
validates :label,
:presence => true,
:uniqueness => { :scope => :page_id }
+
+ def save_file
+ p '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'
+ p self.content
+ p self.content.class.name
+ end
end
app/views/cms_admin/pages/edit.html.erb +1 -1
@@ @@ -6,6 +6,6 @@
<%= render :partial => 'cms_admin/sites/mirrors', :object => @page %>
<% end %>
- <%= cms_form_for @page, :as => :page, :url => {:action => :update} do |form| %>
+ <%= cms_form_for @page, :as => :page, :url => {:action => :update}, :html => {:multipart => true} do |form| %>
<%= render :partial => 'form', :object => form %>
<% end %>
app/views/cms_admin/pages/new.html.erb +1 -1
@@ @@ -1,5 +1,5 @@
<h1><%= t('.title') %></h1>
- <%= cms_form_for @page, :as => :page, :url => {:action => :create} do |form| %>
+ <%= cms_form_for @page, :as => :page, :url => {:action => :create}, :html => {:multipart => true} do |form| %>
<%= render :partial => 'form', :object => form %>
<% end %>
comfortable_mexican_sofa/form_builder.rb b/lib/comfortable_mexican_sofa/form_builder.rb +19 -0
@@ @@ -118,4 +118,23 @@ class ComfortableMexicanSofa::FormBuilder < ActionView::Helpers::FormBuilder
default_tag_field(tag, :content_field_method => :text_area_tag)
end
+ def file(tag)
+ default_tag_field(tag, :content_field_method => :file_field)
+ end
+
+ def collection(tag)
+ options = [["---- Select #{tag.collection_class.titleize} ----", nil]] +
+ tag.collection_objects.collect do |m|
+ [m.send(tag.collection_title), m.send(tag.collection_identifier)]
+ end
+
+ content = @template.select_tag(
+ 'page[blocks_attributes][][content]',
+ @template.options_for_select(options, :selected => tag.content),
+ :id => nil
+ )
+ content << @template.hidden_field_tag('page[blocks_attributes][][label]', tag.label, :id => nil)
+ simple_field(tag.label, content, :class => tag.class.to_s.demodulize.underscore )
+ end
+
end
comfortable_mexican_sofa/tag.rb b/lib/comfortable_mexican_sofa/tag.rb +1 -1
@@ @@ -93,7 +93,7 @@ module ComfortableMexicanSofa::Tag
# Checks if this tag is using Cms::Block
def is_cms_block?
- %w(page field).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
+ %w(page field collection file).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
end
# Used in displaying form elements for Cms::Block