{"id":87,"date":"2007-12-23T19:00:00","date_gmt":"2007-12-23T19:00:00","guid":{"rendered":"\/2008\/07\/30\/simple-cms-plugin-for-ruby-on-rails"},"modified":"2009-08-30T04:44:41","modified_gmt":"2009-08-30T04:44:41","slug":"simple-cms-plugin-for-ruby-on-rails","status":"publish","type":"post","link":"http:\/\/pullmonkey.com\/2007\/12\/23\/simple-cms-plugin-for-ruby-on-rails\/","title":{"rendered":"Simple CMS Plugin for Ruby on Rails Tutorial"},"content":{"rendered":"

The SimpleCMS Plugin<\/h1>\n

Created by Slaive and PullMonkey (December 2007)<\/p>\n

Check out the demo<\/a> - http:\/\/pullmonkey.com\/projects\/simple_cms<\/a><\/p>\n

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.<\/p>\n

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<\/p>\n\n\n
\n
1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt><\/pre>\n<\/td>\n
\n
\n<\/tt>From<\/span>:\n<\/tt>  self<\/span>.view_paths << File<\/span>.join(File<\/span>.dirname(__FILE__<\/span>), '<\/span>..<\/span>'<\/span><\/span>, '<\/span>views<\/span>'<\/span><\/span>)\n<\/tt>\n<\/tt>To<\/span>:\n<\/tt>  self<\/span>.template_root = File<\/span>.join(File<\/span>.dirname(__FILE__<\/span>), '<\/span>..<\/span>'<\/span><\/span>, '<\/span>views<\/span>'<\/span><\/span>)\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

Imaging Processor<\/h2>\n

For this plugin to be fully functional you will need to install one of the following Image Processing gems:<\/p>\n

    \n
  • ImageScience - A light inline-Ruby library that only resizes images.<\/li>\n
  • RMagick - The grand-daddy, both in terms of advanced image processing features and memory usage.<\/li>\n
  • minimagick - It's much easier on memory than RMagick because it runs the ImageMagick command in a shell.<\/li>\n<\/ul>\n

    Any one of these gems will work.<\/p>\n

    <\/p>\n

    Install SimpleCMS and Dependencies<\/h2>\n\n\n
    \n
    1\n<\/tt>2\n<\/tt>3\n<\/tt><\/pre>\n<\/td>\n
    \n
    \n<\/tt>ruby script\/plugin install http:\/\/svn.pullmonkey.com\/plugins\/trunk\/simple_cms\/\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

    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<\/p>\n\n\n
    \n
    1\n<\/tt>2\n<\/tt>3\n<\/tt><\/pre>\n<\/td>\n
    \n
    \n<\/tt>rake simple_cms:install_dependencies\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

    However if this doesn't work then you can do it the normal way:<\/p>\n\n\n
    \n
    1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt><\/pre>\n<\/td>\n
    \n
    \n<\/tt>ruby script\/plugin install http:\/\/svn.pullmonkey.com\/plugins\/trunk\/attachment_fu\/\n<\/tt>ruby script\/plugin install http:\/\/svn.pullmonkey.com\/plugins\/trunk\/responds_to_parent\/\n<\/tt>ruby script\/plugin install http:\/\/svn.pullmonkey.com\/plugins\/trunk\/acts_as_versioned\/\n<\/tt>ruby script\/plugin install http:\/\/svn.pullmonkey.com\/plugins\/trunk\/coderay\/\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

    <\/p>\n

    The Javascript\/css Files<\/h2>\n

    This plugin requires a great deal of javascript and css files that will need to be copied to the corresponding folder in your public\/<\/i> directory. These files are located in the simple_cms\/assets\/<\/i> directory.<\/p>\n

    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.<\/p>\n\n\n
    \n
    1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt><\/pre>\n<\/td>\n
    \n
    \n<\/tt>rake simple_cms:install\n<\/tt>rake simple_cms:uninstall\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

    <\/p>\n

    Creating the Tables<\/h2>\n

    You will need to create 3 tables in your database.<\/p>\n

      \n
    • simple_cms_items<\/li>\n
    • simple_cms_images<\/li>\n
    • simple_cms_media<\/li>\n<\/ul>\n

      To have the migration tables generated for you use this command:<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>ruby script\/generate simple_cms_migrations\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      The tables should look like this:<\/p>\n

      create_simple_cms_items.rb<\/h3>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt>20<\/strong>\n<\/tt>21\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>class<\/span> CreateSimpleCmsItems<\/span> < ActiveRecord<\/span>::Migration<\/span>\n<\/tt>  def<\/span> self<\/span>.up\n<\/tt>    create_table :simple_cms_items<\/span> do<\/span> |t|\n<\/tt>      t.column :params<\/span>,     :string<\/span>\n<\/tt>      t.column :data<\/span>,       :text<\/span>\n<\/tt>      t.column :position<\/span>,   :integer<\/span>\n<\/tt>      t.column :created_at<\/span>, :datetime<\/span>\n<\/tt>      t.column :updated_at<\/span>, :datetime<\/span>\n<\/tt>      t.column :created_by<\/span>, :string<\/span>\n<\/tt>      t.column :updated_by<\/span>, :string<\/span>\n<\/tt>    end<\/span>\n<\/tt>    SimpleCmsItem<\/span>.create_versioned_table\n<\/tt>  end<\/span>\n<\/tt>\n<\/tt>  def<\/span> self<\/span>.down\n<\/tt>    SimpleCmsItem<\/span>.drop_versioned_table\n<\/tt>    drop_table :simple_cms_items<\/span>\n<\/tt>  end<\/span>\n<\/tt>end<\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      create_simple_cms_images.rb<\/h3>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>class<\/span> CreateSimpleCmsImages<\/span> < ActiveRecord<\/span>::Migration<\/span>\n<\/tt>  def<\/span> self<\/span>.up\n<\/tt>    create_table :simple_cms_images<\/span> do<\/span> |t|\n<\/tt>      t.column :parent_id<\/span>,    :integer<\/span>\n<\/tt>      t.column :content_type<\/span>, :string<\/span>\n<\/tt>      t.column :filename<\/span>,     :string<\/span>\n<\/tt>      t.column :thumbnail<\/span>,    :string<\/span>\n<\/tt>      t.column :size<\/span>,         :integer<\/span>\n<\/tt>      t.column :width<\/span>,        :integer<\/span>\n<\/tt>      t.column :height<\/span>,       :integer<\/span>\n<\/tt>    end<\/span>\n<\/tt>  end<\/span>\n<\/tt>\n<\/tt>  def<\/span> self<\/span>.down\n<\/tt>    drop_table :simple_cms_images<\/span>\n<\/tt>  end<\/span>\n<\/tt>end<\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      create_simple_cms_medias.rb<\/h3>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt>12\n<\/tt>13\n<\/tt>14\n<\/tt>15<\/strong>\n<\/tt>16\n<\/tt>17\n<\/tt>18\n<\/tt>19\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>class<\/span> CreateSimpleCmsMedias<\/span> < ActiveRecord<\/span>::Migration<\/span>\n<\/tt>  def<\/span> self<\/span>.up\n<\/tt>    create_table :simple_cms_medias<\/span> do<\/span> |t|\n<\/tt>      t.column :parent_id<\/span>,    :integer<\/span>\n<\/tt>      t.column :content_type<\/span>, :string<\/span>\n<\/tt>      t.column :filename<\/span>,     :string<\/span>\n<\/tt>      t.column :thumbnail<\/span>,    :string<\/span>\n<\/tt>      t.column :size<\/span>,         :integer<\/span>\n<\/tt>      t.column :width<\/span>,        :integer<\/span>\n<\/tt>      t.column :height<\/span>,       :integer<\/span>\n<\/tt>    end<\/span>\n<\/tt>  end<\/span>\n<\/tt>\n<\/tt>  def<\/span> self<\/span>.down\n<\/tt>    drop_table :simple_cms_medias<\/span>\n<\/tt>  end<\/span>\n<\/tt>end<\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      There is one more migration file you should have. It's called change_items_data_colmn<\/b> and it looks like this:<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>class<\/span> ChangeItemsDataColumn<\/span> < ActiveRecord<\/span>::Migration<\/span>\n<\/tt>  def<\/span> self<\/span>.up\n<\/tt>    change_column :simple_cms_items<\/span>, :data<\/span>, :text<\/span>, :limit<\/span> => 10000000<\/span>\n<\/tt>  end<\/span>\n<\/tt>\n<\/tt>  def<\/span> self<\/span>.down\n<\/tt>    change_column :simple_cms_items<\/span>, :data<\/span>, :text<\/span>\n<\/tt>  end<\/span>\n<\/tt>end<\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      This is a change to the simple_cms_items<\/b> table data<\/b> column. This allows you to store up to 10 megabytes of text instead of the 65 kilobytes it defaulted to.<\/p>\n

      <\/p>\n

      Remember to rake your tables into your databases once you have generated them.<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt>rake db:migrate\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      Javascript and css Include Tags<\/h2>\n

      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<\/i> should look something like this:<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt>7\n<\/tt>8\n<\/tt>9\n<\/tt>10<\/strong>\n<\/tt>11\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt><html><\/span>\n<\/tt>  <head><\/span>\n<\/tt>    <%= javascript_include_tag :defaults, "simple_cms" %><\/span>\n<\/tt>    <%= stylesheet_link_tag "simple_cms", "coderay" %><\/span>\n<\/tt>  <\/head><\/span>\n<\/tt>  <body><\/span>\n<\/tt>    <%= yield %><\/span>\n<\/tt>  <\/body><\/span>\n<\/tt><\/html><\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      In Your View<\/h2>\n

      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:<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt><%=<\/span> render :simpleCMS<\/span> => "<\/span>YourLabel<\/span>"<\/span><\/span>, :admin<\/span> => true<\/span> %><\/span><\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n

      Here is another example with more options:<\/p>\n\n\n
      \n
      1\n<\/tt>2\n<\/tt>3\n<\/tt>4\n<\/tt>5<\/strong>\n<\/tt>6\n<\/tt><\/pre>\n<\/td>\n
      \n
      \n<\/tt><%=<\/span> render :simpleCMS<\/span> => "<\/span>label<\/span>"<\/span><\/span>, :admin<\/span> => true<\/span>,\n<\/tt>                                  :user<\/span> => "<\/span>UserName<\/span>"<\/span><\/span>,\n<\/tt>                                  :prefix<\/span> => "<\/span>\/whatever\/your\/prefix\/is<\/span>"<\/span><\/span>,\n<\/tt>                                  :reusable<\/span> => true<\/span> %><\/span><\/span>\n<\/tt>\n<\/tt><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n
        \n
      • :simpleCMS<\/i> takes a label. Changing this label means losing all your current content and creating a new one. However, you can always change it back.<\/li>\n
      • :admin<\/i> takes true or false. The default is false. If you pass true then when you run your mouse over the content a blue highlight box will appear and you will be able to click on the box and edit the content. If you pass false then you will only be able to see the content but not edit any of it.<\/li>\n
      • :user<\/i> is optional and it takes any string you pass it.<\/li>\n
      • :prefix<\/i> is optional. This is where you pass your prefix if you have one.<\/li>\n
      • :reusable<\/i> takes true or false. Default is false. Set this true if you want to use this same content on multiple pages. The label must be the same on all pages you are using this content. *NOTE* you will lose all current data for this content if you change this as it gives the content a different id and changes the params of how it is called.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"

        The SimpleCMS Plugin 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 […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6,3,14,5,9,28],"tags":[60,61,65,210,211,43,214],"_links":{"self":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/87"}],"collection":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/comments?post=87"}],"version-history":[{"count":1,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/87\/revisions"}],"predecessor-version":[{"id":57361,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/posts\/87\/revisions\/57361"}],"wp:attachment":[{"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/media?parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/categories?post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pullmonkey.com\/wp-json\/wp\/v2\/tags?post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}