=Casein - a lightweight CMS toolkit for Ruby on Rails, based on Bootstrap ** ALL-NEW CASEIN 5.1.1 — featuring new responsive UI based on Bootstrap 3.3! ** Casein is a Rails 4.x gem that provides scaffolding generators and helper functions to quickly create a clean and minimal CRUD interface for your data. It comes with a pre-rolled user-authentication system, supports user-based timezones, and is mobile ready. As Casein is completely decoupled from the front end, it can be added to new or existing Rails projects, or used as a standalone CMS to drive platforms built on other technologies. Screenshots at: http://www.caseincms.com ==Requirements This version of Casein is designed for Ruby on Rails 4.x and Ruby 2.x. ==What’s New in 5.1.1 Casein 5.1.1 has the following updates: * Fixes for Rails 4.2 compatibility * Added new Casein helpers for HTML5 form helpers (see “Changing form elements” below) * First steps in building a test suite * Switched from Jeweler to Bundler for gem distribution Version 5.1.1 should be a drop-in replacement for 5.1.0 Thanks to @bunnymatic for this release. ==What Was New in 5.1.0 * Finally updated to Boostrap 3.3 (all bundled Bootstrap files removed in favor of bootstrap-sass gem) * Rake task to create admin user now takes an optional password * Authlogic version bumped to 3.4.3 * UI tweaks Version 5.1.0 should be a drop-in replacement for 5.0.0 ==What Was New in 5.0.0 * Now based on Bootstrap 3 * Complete UI overhaul, now mobile-first * Support for strong parameters * Support for asset pipeline * Rails 4 compatibility fixes * Many other tweaks and improvements over Casein 3.x and 4.x ==Installation — Create a new Rails project (or use an existing one) and enter the project directory from a terminal prompt. — Add the Casein gem to your Gemfile: gem 'casein', '~>5.1.1' — Then use bundler to install Casein and its dependencies: bundle install — If you have just created a new project — and don't want to use the default SQLite settings — then remember to add your database details to /config/database.yml at this point. — To enable Casein notification emails (used for new users and forgotten passwords) then add your SMTP server information to your initializers. For development, you can use something cool like MailCatcher (http://mailcatcher.me) — Install Casein configuration files into your project. This should not be run more than once without backing up or merging the generated files, as your customisations will be overwritten: rails g casein:install — Perform a database migration to create the Casein users table: rake db:create (if needed) rake db:migrate — Run the following Rake task to set up an initial user. You should specify your email address and password (or omit the password parameter to have a random password assigned.) If you've set up an SMTP server in your Rails environment then you’ll also receive an email notification about the new account. rake casein:users:create_admin email=you@yourdomain.com [password=your_password] — Run your app! (rebooting the web server if applicable) — You can access Casein at http://yourdomain.com/casein or http://yourdomain.com/admin Casein should now be running! ==Usage The default Casein install supports user authentication. Users may have a role of either ‘administrator’ or ‘user’. The former is allowed to add, edit and delete other Casein users. The latter is only allowed to edit their own profile. Casein is a framework allowing you to quickly build up an interface to edit and create new records from your database model. As well as the user support and user interface, there are many configurations and generators to help you along the way. ==Scaffolding Casein has a scaffolding generator to automatically create all the CRUD views and controllers for your project models. This is the fastest way to add Casein support to your project. The command to run the scaffolding generator is: rails g casein:scaffold ModelName [field:type, field:type] Where: * ModelName – The *singular* name of your model, e.g. Customer * field:type – The name of your database fields and their types, e.g. name:string. The field name must match the name in your migrations and the type must be one of the Rails migration types (string, text, integer, float, decimal, datetime, timestamp, time, date, binary, boolean). Note that you do not have to specify all of the fields in your model, but just the ones that you wish to be editable in Casein. e.g. a typical scaffolding command might look like: rails g casein:scaffold Customer name:string age:integer date_of_birth:date has_paid:boolean By default the scaffold generator expects the model and database migration to already exist. This is because you typically won't want all of your model attributes to be editable in Casein. So you'd set up your model and migration the usual way, then run the Casein scaffold generator just for the appropriate attributes. However, you can add --create-model-and-migration to the generator to also create these files at the same time. Command-line options that can be added to the end of the scaffold generate command: --create-model-and-migration = Also creates a model and migration. --read-only = Creates scaffolding to view model data only (you will not be able to edit, create, or delete records). This is useful if you want to create a read-only viewer of data that's generated elsewhere. --no-index = Excludes the index view and does not add the model to the navigation. The _table partial is still generated. This is useful when generating has/belongs relationships. Once the command has been executed, the generator will: * Add a new tab for the model to: app/views/casein/layouts/_tab_navigation.html.erb * Create a controller with the name: app/controllers/casein/model_controller.erb * Add views for index, new and show to: app/views/casein/model/ * If you restart and run your application now, you’ll be able to sign in to Casein and directly edit and create new instances of your model data right away! However, you’ll want to customise your views and side bars and extend your controller to suit your project. The scaffold generator just sets up the defaults for you. NOTE: Once you start customising the generated scaffolding files, you should be aware that if you run the generator again you should not overwrite the changed files without backing them up first. The generator will warn you each time it finds a file that you’ve customised. If you run the scaffold generator from a new version of Casein, then you should manually merge your backup and the new file. You can of course however, leave your originals untouched. ==General Configuration app/helpers/casein/config_helper.rb This is the main Casein configuration file that allows you to change things such as the website name, logo, notification email address, dashboard URL, etc. The options are documented within the file. To change the default page that Casein shows, you should change casein_config_dashboard_url. For example, to just go straight to the index page for a model named Page, you'd use: def casein_config_dashboard_url url_for casein_pages_path end views/casein/layouts/_tab_navigation.html.erb An ERB partial for the the left navigation tabs. Note that using the scaffolding generator will automatically add tabs into this file, but it can also be manually edited and rearranged. view/casein/layouts/_top_navigation.html.erb An ERB partial for adding items to the top navigation. /assets/javascripts/casein/custom.js & /assets/stylesheets/casein/custom.css.scss These files are added to your app’s /assets directory. They allow you to add custom JavaScript or CSS to your Casein deployment. ==Customising Once you have the Casein core installed and configured, and have added support for your models with the scaffolding generator, you’ll want to extend it so that it actually has some functionality for your project! Rules and conventions * Casein extension controllers and helpers should be namespaced to 'Casein::' * Casein extension controllers should derive from Casein::CaseinController and not ApplicationController * To set the page title, your controller action should set @casein_page_title. If this is not set, then Casein will use a default created from your project name. Sidebar The sidebar in Casein should be used for view specific actions, e.g. "Add user" for users/index, or "Back to list", "Delete user" for users/show. To specify the contents of the sidebar, you must add a 'content_for :sidebar' block in the relevant view file (index, show, etc.) e.g.: <%= content_for :sidebar do %>