Simple CMS Plugin for Rails Demo
I have placed a nice little demo of this plugin under Pullmonkey Projects - http://pullmonkey.com/projects/simple_cms.
Please let us know what works, what does not work.
Thank you.
I have placed a nice little demo of this plugin under Pullmonkey Projects - http://pullmonkey.com/projects/simple_cms.
Please let us know what works, what does not work.
Thank you.
Created by Slaive and PullMonkey (December 2007)
Check out the demo - http://pullmonkey.com/projects/simple_cms
This is still a work in progress so feel free to notify me of any bugs, problems, or suggestions of how to make it better.
This plugin is built for rails 2.0.2. So if you are using an older version of rails then you will need to edit each of the controllers
1 2 3 4 5 6 7 |
From: self.view_paths << File.join(File.dirname(__FILE__), '..', 'views') To: self.template_root = File.join(File.dirname(__FILE__), '..', 'views') |
For this plugin to be fully functional you will need to install one of the following Image Processing gems:
Any one of these gems will work.
1 2 3 |
ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/simple_cms/ |
The simple_cms plugin requires the attachment_fu, responds_to_parent, acts_as_versioned, and coderay plugins as well. To make this easier I there is a built-in rake process
1 2 3 |
rake simple_cms:install_dependencies |
However if this doesn't work then you can do it the normal way:
1 2 3 4 5 6 |
ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/attachment_fu/ ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/responds_to_parent/ ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/acts_as_versioned/ ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/coderay/ |
This plugin requires a great deal of javascript and css files that will need to be copied to the corresponding folder in your public/ directory. These files are located in the simple_cms/assets/ directory.
These files should have been copied over when you install the plugin. However, I built in a couple rake task commands to help you out installing and uninstalling these files if you need to.
1 2 3 4 |
rake simple_cms:install rake simple_cms:uninstall |
You will need to create 3 tables in your database.
To have the migration tables generated for you use this command:
1 2 3 |
ruby script/generate simple_cms_migrations |
The tables should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class CreateSimpleCmsItems < ActiveRecord::Migration def self.up create_table :simple_cms_items do |t| t.column :params, :string t.column :data, :text t.column :position, :integer t.column :created_at, :datetime t.column :updated_at, :datetime t.column :created_by, :string t.column :updated_by, :string end SimpleCmsItem.create_versioned_table end def self.down SimpleCmsItem.drop_versioned_table drop_table :simple_cms_items end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class CreateSimpleCmsImages < ActiveRecord::Migration def self.up create_table :simple_cms_images do |t| t.column :parent_id, :integer t.column :content_type, :string t.column :filename, :string t.column :thumbnail, :string t.column :size, :integer t.column :width, :integer t.column :height, :integer end end def self.down drop_table :simple_cms_images end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class CreateSimpleCmsMedias < ActiveRecord::Migration def self.up create_table :simple_cms_medias do |t| t.column :parent_id, :integer t.column :content_type, :string t.column :filename, :string t.column :thumbnail, :string t.column :size, :integer t.column :width, :integer t.column :height, :integer end end def self.down drop_table :simple_cms_medias end end |
There is one more migration file you should have. It's called change_items_data_colmn and it looks like this:
1 2 3 4 5 6 7 8 9 10 11 |
class ChangeItemsDataColumn < ActiveRecord::Migration def self.up change_column :simple_cms_items, :data, :text, :limit => 10000000 end def self.down change_column :simple_cms_items, :data, :text end end |
This is a change to the simple_cms_items table data column. This allows you to store up to 10 megabytes of text instead of the 65 kilobytes it defaulted to.
Remember to rake your tables into your databases once you have generated them.
1 2 3 |
rake db:migrate |
You will need to make sure you have javascript include tags for your defaults and simple_cms and stylesheet link tags for the simple_cms and coderay stylesheets. Your app/views/layouts/application.rhtml should look something like this:
1 2 3 4 5 6 7 8 9 10 11 |
<html> <head> <%= javascript_include_tag :defaults, "simple_cms" %> <%= stylesheet_link_tag "simple_cms", "coderay" %> </head> <body> <%= yield %> </body> </html> |
Having the simple_cms plugin show up is really pretty simple. Anywhere you want to have the simple_cms to show up you put one line as simple as this:
1 2 3 |
<%= render :simpleCMS => "YourLabel", :admin => true %>
|
Here is another example with more options:
1 2 3 4 5 6 |
<%= render :simpleCMS => "label", :admin => true,
:user => "UserName",
:prefix => "/whatever/your/prefix/is",
:reusable => true %>
|
1 2 3 4 5 6 7 8 |
<%= date_select "object", "attr", :index => "", :start_year => Date.today.year, :discard_day => true, :disabled => true, :order => [:month, :year] %> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<input id="object__attr_3i" type="hidden" value="1" name="object[object_attributes][][attr(3i)]"/> <select id="object_attr_attributes__attr_2i" disabled="disabled" name="object[object_attributes][][attr(2i)]"> ... </select> <select id="object_attributes__attr_1i" disabled="disabled" name="object[object_attributes][][attr(1i)]"> ... </select> |
Note that this may be fixed now in version 2.0 of rails. So the problem arises when you use both the options of disabled and discard for the date_select helper. By themselves they work fine and without problems. When you use them together the discard option overrides the disabled option. In the example above, I discard the day and want the entire element to be disabled. The resulting HTML hides the day selector but does not disable it. So, when the form is submitted the date select day is bundled in with the rest of the parameters as a hash of just the day. If it had been hidden and disabled, then we could have ignored it.
hidden_html(...) is used anytime discard_<something> is set to true.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
module ActionView module Helpers ... module DateHelper ... def hidden_html(type, value, options) name_and_id_from_options(options, type) hidden_html = %(<input type="hidden" id="#{options[:id]}" name="#{options[:name]}" value="#{value}" />\n) end ... end end end |
Note that in the above code there is no reference to the disabled parameter that was set. Using a mixin, you can create a file in RAILS_ROOT/lib named date_select_fix.rb with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
module ActionView module Helpers ... module DateHelper ... def hidden_html(type, value, options) name_and_id_from_options(options, type) hidden_html = %(<input type="hidden" id="#{options[:id]}" name="#{options[:name]}" value="#{value}"#{" disabled=\"disabled\"" if options[:disabled]} />\n) end ... end end end |
Works for me. Just for the record, the project that I found this bug in is still using rails 1.2.1 and actionpack 1.13.1.