Home > scully-rails-template

scully-rails-template

Scully-rails-template is a project mainly written in RUBY and JAVASCRIPT, based on the MIT license.

Workhorse Rails template used at ScullyTown

h1. ScullyTown Rails Template

A workhorse Rails 2.3 template we use for the majority of our projects, based on the original "Thoughtbot Suspenders template":http://github.com/thoughtbot/suspenders.

Note: This is a work-in progress and continually updated. Please feel free to fork this project and make it better!

h3. How to use

To use this template, run the following command:


  rails -d mysql -m http://github.com/scullygroup/scully-rails-template/raw/master/scullyonrails.rb /path/to/app/appname

When the template setup has finished, be sure to configure database.yml and then run the following:


  rake project:setup

This will:

  • Generate the comatose plugin_migration
  • Generate the wysihat_engine migration
  • Generate a migration to index the users table
  • Run all pending migrations
  • Populate Roles table with seed data

An initial admin user is also setup with the following credentials:

You might want to change this after your app is setup ;)

You can login to the app by going to /login.

h3. Key Features

  • User Authentication using AuthLogic
  • Email verification for user accounts created using AuthLogic
  • Comatose CMS installed as a Rails Engine
  • Wysihat WYSIWYG editor
  • Comatose Rake-n-Bake support for populating page tree from Freemind sitemap, "http://github.com/scullygroup/Comatose-Rake-n-Bake/tree/":http://github.com/scullygroup/Comatose-Rake-n-Bake/tree/
  • Role-based authentication with reserved roles (admin, publisher, writer, user)

A Word About Roles When the app is generated from the template, a few reserved roles are created:

  • Admin, full access to entire app
  • Publisher, full access to CMS
  • Writer, read/write access to entire CMS, but no publishing rights
  • User, login/logout functionality only, cannot access any backend controller actions (this is the low-level user role upon account creation)

From here, you can create additional "writer-level" roles that can be assigned to parent pages in the CMS. For example, you could create a role called "Human Resources", which could be assigned access to the "About Us" parent page and all of it's children. Currently, only one role can be assigned per parent.

When a "writer-level" user creates/edits a page, an email is sent to the user(s) in the Publisher role prompting them to login and review the page before publishing.

h3. What's installed

Plugins haml-scaffold, "http://github.com/tobias/haml-scaffold":http://github.com/tobias/haml-scaffold hoptoad_notifier, "http://github.com/thoughtbot/hoptoad_notifier.git":http://github.com/thoughtbot/hoptoad_notifier.git limerick_rake, "http://github.com/thoughtbot/limerick_rake":http://github.com/thoughtbot/hoptoad_notifier.git jrails, "http://code.google.com/p/ennerchi":http://code.google.com/p/ennerchi admin_data, "http://github.com/neerajdotname/admin_data":http://github.com/neerajdotname/admin_data engines, "http://github.com/lazyatom/engines":http://github.com/lazyatom/engines comatose_engine, "http://github.com/bcalloway/comatose-engine":http://github.com/bcalloway/comatose-engine

Gems will_paginate, "http://github.com/mislav/will_paginate":http://github.com/mislav/will_paginate mocha, "http://github.com/floehopper/mocha":http://github.com/floehopper/mocha factory_girl, "http://github.com/thoughtbot/factory_girl":http://github.com/thoughtbot/factory_girl shoulda, "http://github.com/thoughtbot/shoulda":http://github.com/thoughtbot/shoulda paperclip, "http://github.com/thoughtbot/paperclip":http://github.com/thoughtbot/paperclip newrelic_rpm, "http://github.com/smtlaissezfaire/newrelic_rpm":http://github.com/smtlaissezfaire/newrelic_rpm haml, "http://github.com/nex3/haml":http://github.com/nex3/haml authlogic, "http://github.com/binarylogic/authlogic":http://github.com/binarylogic/authlogic searchlogic, "http://github.com/binarylogic/searchlogic":http://github.com/binarylogic/searchlogic justinfrench-formtastic, "http://github.com/justinfrench/formtastic":http://github.com/justinfrench/formtastic rubyist-aasm, "http://github.com/rubyist/aasm":http://github.com/rubyist/aasm wysihat-engine, "http://github.com/80beans/wysihat-engine":http://github.com/80beans/wysihat-engine

Note: Gems are sourced from GemCutter. If you have not installed the GemCutter gem, please follow the instructions "here":http://gemcutter.org/pages/gem_docs

h3. Before Filters

There are a few before filters defined in the app that can be used across other models.


  require_user

Before filter that requires a user to be logged-in to access controller actions


  check_authorization(vars)

Simple role authorization, checks to see if current user's role in present in the vars array.
For example, a before_filter is placed at the top of any controller that needs authorization. Actions can be specified, as well as an array of roles:


 before_filter :except => [:show, :edit, :update, :no_role] do |controller|
   controller.check_authorization(["admin", "writer"])
 end

  check_role

A before filter that ensures a user cannot access another user's records unless they are an admin

h3. Helper Methods

Since this app template uses jRails and jQuery (instead of Prototype), a helper is created that will allow you to include the Prototype libraries instead of jQuery (with jRails, the defaults are currently jQuery).

To use Prototype, include the following helper in the head of your layout:


  javascript_include_tag :prototype

Be sure to uncomment the jQuery.noConflict(); line in plugins/jrails/init.rb if you plan on using jQuery alongside Prototype. Also, in the head of your layout file, add the following after referencing your javascript libraries:


  

Note: This app template depends on jRails. You may need to tweak the settings in vendor/plugins/jrails/rails/init.rb for jQuery.noConflict();

An example jQuery function would then be written like this:


  jQuery(document).ready(function($){
    $('#div').click(function(){
      $('#other-div').hide();
    });
  });

There are also a few key helper methods defined in the app that can be used across other models.


  current_user

Returns the current, logged-in user


  role_call

Returns the role name of the current user


  cms_admin

Returns true if the current user has the "admin" or "publisher" role


  redirect_based_on_role(target)

Redirect for controller actions that redirects to the target if user is an admin, otherwise redirect to their profile. For example, if the use is an admin, this will redirect them to the "/users" url redirect_based_on_role("/users")

h3. What's setup

When the template is generated, the following occurs:

  • All the above plugins and gems are installed and vendored.
  • User Session is generated
  • User Sessions Controller is generated
  • User model and database migration is generated
  • Users controller is generated
  • Email verification mailers for Authlogic
  • Formtastic generator is run
  • Comatose Engine migrations are run
  • Baseline app structure is generated application_controller.rb specifics environment.rb configuration Capistrano envrionment-specific recipes are installed Actionmailer initializer created as action_mailer_configs.rb with Gmail settings smtp_tls.rb created for use with Gmail and ActionMailer assets in public directory are migrated Misc initializers are created Basic routes are installed in routes.rb
  • Project is initalized as a git repo, all files added, and initial commit message made

ActionMailer config is setup in config/initializers/action_mailer_configs.rb

At the end of the generation, the base views, models, and controllers for AuthLogic as well as admin and application layouts are installed as follows:


  |____app
  | |____controllers
  | | |____application_controller.rb
  | | |____comatose_admin_controller.rb
  | | |____comatose_controller.rb
  | | |____roles_controller.rb
  | | |____user_sessions_controller.rb
  | | |____user_verifications_controller.rb
  | | |____users_controller.rb
  | |____helpers
  | | |____comatose_admin_helper.rb
  | |____models
  | | |____comatose_page.rb
  | | |____notifier_mailer.rb
  | | |____publisher_mailer.rb
  | | |____role.rb
  | | |____user.rb
  | | |____user_session.rb
  | |____views
  | | |____comatose_admin
  | | | |_____form.html.haml
  | | | |_____page_list_item.html.haml
  | | | |_____sortable.html.erb
  | | | |_____toggle_state.html.haml
  | | | |____delete.html.haml
  | | | |____edit.html.haml
  | | | |____index.html.haml
  | | | |____new.html.haml
  | | | |____reorder.html.haml
  | | | |____versions.html.haml
  | | |____layouts
  | | | |_____admin_nav.html.haml
  | | | |_____flashes.html.haml
  | | | |_____user_bar.html.haml
  | | | |____application.html.haml
  | | | |____comatose_admin.html.haml
  | | |____notifier_mailer
  | | | |____verification_instructions.html.haml
  | | |____publisher_mailer
  | | | |____approve_page.html.haml
  | | |____roles
  | | | |_____form.html.haml
  | | | |_____secondary_nav.html.haml
  | | | |____edit.html.haml
  | | | |____index.html.haml
  | | | |____new.html.haml
  | | |____user_sessions
  | | | |____new.html.haml
  | | |____users
  | | | |_____form.html.haml
  | | | |_____secondary_nav.html.haml
  | | | |____edit.html.haml
  | | | |____index.html.haml
  | | | |____new.html.haml
  | | | |____no_role.html.haml
  | | | |____show.html.haml
  |____public
  | |____images
  | | |____flash-check.png
  | | |____flash-error.png
  | | |____flash-warning.png
  | |____javascripts
  | | |____scriptaculous.js
  | |____stylesheets
  | | |____reset.css
  | | |____sass
  | | | |____admin.sass
  | | | |____screen.sass
  | | | |____theme.sass
  |____test
  | |____factories
  | | |____factory.rb
  | |____functional
  | | |____comatose_admin_controller_test.rb
  | | |____comatose_controller_test.rb
  | | |____roles_controller_test.rb
  | | |____user_sessions_controller_test.rb
  | | |____user_verifications_controller_test.rb
  | | |____users_controller_test.rb
  | |____unit
  | | |____comatose_page_test.rb
  | | |____notifier_mailer_test.rb
  | | |____publisher_mailer_test.rb
  | | |____role_test.rb
  | | |____user_test.rb

Copyright © 2009 The Scully Group, released under the MIT license

Previous:daterange