A block, as used within this gem, is a section of content (either an image, simple text, or rich text that includes markup). This gem allows you to create these different types of blocks, and place them throughout the site. You can then give the administrative users of the site access to edit these blocks.
- Your app must already have functional devise installation
- Your app must already have functional cancancan installation
- Your app must already have functional ckeditor installation
- Your
User
must have arole
field - Administrators must be identified by having a
role
value of 'admin' - Your app needs to handle the display of
notice
messages, should they exist - Only rich blocks are available - image & simple text blocks have not been added, yet
Add this line to your application's Gemfile:
gem 'content_block'
Have bundler install the gem:
bundle
Run the installer:
rails generate content_block:install
Optionally, you can copy over the view files in order to have direct control on the admin appearance:
rails generate content_block:views
You can manage the blocks by visiting the /content-block/admin
URL as an admin. That page links out to each block-type's simple CRUD interface.
To use a block in your view without displaying its title
(IDENTIFIER
is either the name
or the id
of the block to be displayed):
<%= rich_block('IDENTIFIER') %>
For example, if a block has an id
of '1' and a name
of 'content page', it can be displayed with either <%= rich_block(1) %>
or <%= rich_block('content page') %>
.
To use a block in your view and display its title
(IDENTIFIER
is either the name
or the id
of the block to be displayed & TAG
is the HTML tag you'd like the title to be wrapped in):
<%= rich_block_with_title('IDENTIFIER', 'TAG') %>
For example, if a block has an id
of '1' and you want to display its title in an <h4>
tag, then it would be displayed with <%= rich_block_with_title(1, 'h4') %>
.
- Fork it ( http://github.com/commonmedia/content_block/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request