Jetter-v1.2
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:Sample Rails application
h1. Rails Application for Devise with CanCan and Twitter Bootstrap

Rails 3.2 example application shows how to use "Devise":http://github.com/plataformatec/devise with "CanCan":https://github.com/ryanb/cancan and "Twitter Bootstrap":http://twitter.github.com/bootstrap/. 

* "Devise":http://github.com/plataformatec/devise gives you ready-made authentication and user management. 
* "CanCan":https://github.com/ryanb/cancan provides authorization for administrator access. 
* "Twitter Bootstrap":http://twitter.github.com/bootstrap/ is a front-end framework for CSS styling. 

Best of all, there's a "detailed tutorial":http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html to show how it's built.

You can clone this app or generate a new Rails application using an "application template":https://github.com/RailsApps/rails3-application-templates.

!http://railsapps.github.com/images/rails3-bootstrap-devise-cancan.png(Rails Application for Devise with CanCan and Twitter Bootstrap)!

h2. !http://twitter-badges.s3.amazonaws.com/t_logo-a.png(Follow on Twitter)!:http://www.twitter.com/rails_apps Follow on Twitter

Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps. Please tweet some praise if you like what you've found.

h2. !http://railsapps.github.com/images/rails-36x36.jpg(Tutorial)! Tutorial

A complete walkthrough tutorial is available on the GitHub wiki:

h4. "View the Tutorial":http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html

The tutorial documents each step to follow to create the application. Every step is documented concisely, so a complete beginner can create this application without any additional knowledge. However, no explanation is offered for any of the steps, so if you are a beginner, you’re advised to look for an introduction to Rails elsewhere. See a list of recommended resources for "Rails":http://railsapps.github.com/rails.html.

If you simply wish to modify the application for your own project, you can download the application and set it up as described below, without following the tutorial.

h2. What Is Implemented -- and What Is Not

This is a demonstration application that allows you to visit a home page and see a list of users. Devise provides user management so a visitor can register with an email address and password and create an account. Devise provides authentication so access to the site can be limited to users who are registered and logged in. CanCan is used for authorization, limiting access to only an administrator for designated pages.

The @rake db:seed@ command sets up a database with two example users. The first user is designated as an administrator and can view a administrative page when logged in. The second user is restricted from accessing the administrative page.

h4. Similar Examples and Tutorials

This example application is based on the "rails3-devise-rspec-cucumber":https://github.com/RailsApps/rails3-devise-rspec-cucumber example and tutorial and adds "CanCan":https://github.com/ryanb/cancan and "Twitter Bootstrap":http://twitter.github.com/bootstrap/. View the "rails3-devise-rspec-cucumber":https://github.com/RailsApps/rails3-devise-rspec-cucumber example and tutorial for the basics of setting up an application with "RSpec":http://rspec.info/ and "Cucumber":http://cukes.info/.

This example application uses ActiveRecord and a SQLite database. You can use the Mongoid ORM with the MongoDB datastore instead, for faster development without schemas or migrations. The "rails3-mongoid-devise":https://github.com/RailsApps/rails3-mongoid-devise example app and tutorial shows how to set up Devise and Mongoid with RSpec and Cucumber.

To see a more complex application that uses Devise, CanCan, and Twitter Bootstrap, see the "rails-prelaunch-signup":https://github.com/RailsApps/rails-prelaunch-signup example and tutorial from the RailsApps project.

See an expanded list of similar "Rails examples, tutorials, and starter apps":http://railsapps.github.com/rails-examples-tutorials.html.

h2. Dependencies

Before generating your application, you will need:

* The Ruby language (version 1.9.3)
* Rails 3.2

Be sure to see "Installing Rails 3.2":http://railsapps.github.com/installing-rails.html for detailed instructions and advice.

h2. Getting the Application

You have several options for getting the code.

h4. Fork, Clone, or Generate?

_Fork:_ If you'd like to add features (or bug fixes) to improve the example application, you can fork the GitHub repo and "make pull requests":http://help.github.com/send-pull-requests/. Your code contributions are welcome!

_Clone:_ If you want to copy and customize the app with changes that are only useful for your own project, you can clone the GitHub repo. You'll need to search-and-replace the project name throughout the application. You probably should generate the app instead (see below).

_Generate:_ If you want to use the project as a starter app for your customized application, use the application template to generate a new version of the example app. You'll be able to give it your own project name when you generate the app. Generating the application (described below) gives you many options, such as using Haml for views, additional Devise modules, and other popular gems such as will-paginate.

h4. Clone the Repository

If you simply wish to examine the example code, you can download the code ("clone the repository") with the command

$ git clone git://github.com/RailsApps/rails3-bootstrap-devise-cancan.git
The source code is managed with Git (a version control system). You'll need Git on your machine (install it from "http://git-scm.com/":http://git-scm.com/). h4. Using the Ready-Made Application Template You can use an application template to generate a new version of the example app. You’ll find an application template for this app in the "Rails Application Templates":https://github.com/RailsApps/rails3-application-templates repository. To build the "rails3-bootstrap-devise-cancan" example application, run the command:
$ rails new myapp -m https://github.com/RailsApps/rails3-application-templates/raw/master/rails3-bootstrap-devise-cancan-template.rb -T
Use the @-T@ flag to skip Test::Unit files. The @$@ character indicates a shell prompt; don't include it when you run the command. This creates a new Rails app (with the name @myapp@) on your computer. The application generator templates will ask you for various preferences. To reproduce the example application exactly as found in the repository, make the following selections: * Would you like to use "Haml":http://en.wikipedia.org/wiki/Haml instead of ERB? *no* * Would you like to use "RSpec":http://rspec.info/ instead of TestUnit? *yes* * Would you like to use "factory_girl":https://github.com/thoughtbot/factory_girl for test fixtures with RSpec? *yes* * Would you like to use "machinist":https://github.com/notahat/machinist for test fixtures with RSpec? *no* * Would you like to use "Cucumber":http://cukes.info/ for your BDD? *yes* * Would you like to use "Guard":http://intridea.com/posts/hire-a-guard-for-your-project to automate your workflow? *no* * Would you like the app to use a Gmail account to send email? *yes* * Would you like to use "Devise":http://github.com/plataformatec/devise for authentication? *#2* ## No ## Devise with default modules ## Devise with Confirmable module ## Devise with Confirmable and Invitable modules * Would you like to manage authorization with "CanCan":https://github.com/ryanb/cancan & "Rolify":https://github.com/EppO/rolify? *yes* * Which front-end framework would you like for HTML5 and CSS3? *#4* ## None ## "Zurb Foundation":http://foundation.zurb.com/ ## "Twitter Bootstrap":http://twitter.github.com/bootstrap/ (less) ## "Twitter Bootstrap":http://twitter.github.com/bootstrap/ (sass) ## "Skeleton":http://www.getskeleton.com/ ## Normalize CSS for consistent styling * Which form gem would you like? *#1* ## None ## simple form ## simple form (bootstrap) * Would you like to use "rails-footnotes":https://github.com/josevalim/rails-footnotes during development? *no* * Would you like to set a robots.txt file to ban spiders? *yes* * Would you like to add 'will_paginate' for pagination? *no* You can choose other selections if you don't care about matching the example application exactly. h4. Use "Recipes" to Customize an Application Template The application template was created using the "rails_apps_composer":https://github.com/RailsApps/rails_apps_composer gem which provides a convenient way to assemble a reusable application template by selecting various "recipes" for popular Rails development packages. Use "rails_apps_composer":https://github.com/RailsApps/rails_apps_composer if you want to customize the application template for your own starter apps. h4. Edit the README If you're open sourcing the app on GitHub, please edit the README file to add a description of the app and your contact info. Changing the README is important if you're using a clone of the example app. I've been mistaken (and contacted) as the author of apps that are copied from my example. h2. Getting Started h4. About Required Gems The application uses the following gems: * "rails":http://rubygems.org/gems/rails * "rspec-rails":http://rubygems.org/gems/rspec-rails * "database_cleaner":http://rubygems.org/gems/database_cleaner * "factory_girl_rails":http://rubygems.org/gems/factory_girl_rails * "cucumber-rails":http://rubygems.org/gems/cucumber-rails * "capybara":http://rubygems.org/gems/capybara * "devise":http://rubygems.org/gems/devise * "cancan":http://rubygems.org/gems/cancan * "rolify":http://rubygems.org/gems/rolify * "bootstrap-sass":http://rubygems.org/gems/bootstrap-sass See "Example Gemfiles for Rails 3.2":http://railsapps.github.com/rails-3-2-example-gemfile.html. h4. Install the Required Gems Install the required gems on your computer: @$ bundle install@ You can check which gems are installed on your computer with: @$ gem list --local@ Keep in mind that you have installed these gems locally. When you deploy the app to another server, the same gems (and versions) must be available. h2. Configure Email You must configure the app for your email account if you want your application to send email messages, for example, if you've generated the application with the option to install the Devise @:confirmable@ module. h4. Use a Gmail account If you've generated the application with the option to use a Gmail account to send email, you'll need to modify the files *config/environments/development.rb* and *config/environments/production.rb* to include your Gmail username and password.
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "example.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}
You can replace @ENV["GMAIL_USERNAME"]@ and @ENV["GMAIL_PASSWORD"]@ with your Gmail username and password. However, committing the file to a public GitHub repository will expose your secret password. If you're familiar with setting "Unix environment variables":http://en.wikipedia.org/wiki/Environment_variable, it's advisable to leave @config.action_mailer.smtp_settings@ unchanged and set your environment variables in the file that is read when starting an interactive shell (the *~/.bashrc* file for the bash shell). This will keep the password out of your repository. Are you using a bash shell? Use @echo $SHELL@ to find out. For a bash shell, edit the *~/.bashrc* file and add:
export GMAIL_USERNAME="myname@gmail.com"
export GMAIL_PASSWORD="secret*"
Open a new shell or restart your terminal application to continue. h4. Configure ActionMailer The example application is set to deliver email in both development and production. It will raise delivery errors in development but not production. In development, @config.action_mailer.default_url_options@ is set for a host at @localhost:3000@ which will enable links in Devise confirmation email messages to work properly. You'll need to change the @config.action_mailer.default_url_options@ host option from @example.com@ to your own domain for the production environment. You can change these values as needed in the *config/environments/development.rb* and *config/environments/production.rb* files. h4. Configure Devise for Email Complete your email configuration by modifying *config/initializers/devise.rb* and setting the @config.mailer_sender@ option for the return email address for messages that Devise sends from the application. h2. Configure Devise You can modify the configuration file for Devise if you want to use something other than the defaults: *config/initializers/devise.rb* h2. Create a Default User h4. Set Up a Database Seed File You'll want to set up a default user so you can easily log in to test the app. You can modify the file *db/seeds.rb* for your own name, email and password:
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user.name
user2 = User.create! :name => 'Second User', :email => 'user2@example.com', :password => 'please', :password_confirmation => 'please'
puts 'New user created: ' << user2.name
user.add_role :admin
Use the defaults or change the values for name, email, and password as you wish. If you've generated the application with the option to install the Devise @:confirmable@ module, there will be an extra attribute @confirmed_at => Time.now@ for creation of a user. h4. Set the Database Prepare the database and add the default user to the database by running the commands:
$ bundle exec rake db:migrate
$ bundle exec rake db:seed
Set the database for running tests:
$ bundle exec rake db:test:prepare
h2. Test the App You can check that your app runs properly by entering the command @$ rails server@ To see your application in action, open a browser window and navigate to "http://localhost:3000/":http://localhost:3000. You should see the default user listed on the home page. When you click on the user's name, you should be required to log in before seeing the user's detail page. To sign in as the first user (the administrator), (unless you've changed it) use * email: user@example.com * password: please You'll see a navigation link for Admin. Clicking the link will display a page with a list of users at "http://localhost:3000/users":http://localhost:3000/users. To sign in as the second user, (unless you've changed it) use * email: user2@example.com * password: please The second user will not see the Admin navigation link and will not be able to access the page at "http://localhost:3000/users":http://localhost:3000/users. h2. Deploy to Heroku For your convenience, here is a "Tutorial for Rails on Heroku":http://railsapps.github.com/rails-heroku-tutorial.html. Heroku provides low cost, easily configured Rails application hosting. h2. Customizing This application provides no useful functionality apart from demonstrating Devise with CanCan and Twitter Bootstrap working together on Rails 3. Add any models, controllers, and views that you need. To see a more complex application that extends this example, see the "rails-prelaunch-signup":https://github.com/RailsApps/rails-prelaunch-signup example and tutorial from the RailsApps project. h2. Testing The example application contains a suite of RSpec unit tests and Cucumber scenarios and step definitions. After installing the application, run @rake -T@ to check that rake tasks for RSpec and Cucumber are available. Run @rake spec@ to run all RSpec tests. Run @rake cucumber@ (or more simply, @cucumber@) to run all Cucumber scenarios. Please send the author a message, create an issue, or submit a pull request if you can contribute improved RSpec or Cucumber files. h2. Troubleshooting Problems? Check the "issues":https://github.com/RailsApps/rails3-application-templates/issues. h4. Problems with "Certificate Verify Failed" Are you getting an error "OpenSSL certificate verify failed" when you try to generate a new Rails app from an application template? See suggestions to resolve the error "Certificate Verify Failed":http://railsapps.github.com/openssl-certificate-verify-failed.html. h2. Documentation and Support This is the only documentation. For a Devise introduction, Ryan Bates offers a "Railscast on Devise":http://railscasts.com/episodes/209-introducing-devise. You can find documentation for "Devise":http://github.com/plataformatec/devise at "http://github.com/plataformatec/devise":http://github.com/plataformatec/devise. There is an active "Devise mailing list":http://groups.google.com/group/plataformatec-devise and you can submit "Devise issues":http://github.com/plataformatec/devise/issues at GitHub. h4. Issues Please create a "GitHub issue":http://github.com/RailsApps/rails3-bootstrap-devise-cancan/issues if you identify any problems or have suggestions for improvements. h4. Where to Get Help Your best source for help with problems is "Stack Overflow":http://stackoverflow.com/questions/tagged/ruby-on-rails-3. Your issue may have been encountered and addressed by others. You can also try "Rails Hotline":http://www.railshotline.com/, a free telephone hotline for Rails help staffed by volunteers. h2. Contributing If you make improvements to this application, please share with others. Send the author a message, create an "issue":http://github.com/RailsApps/rails3-bootstrap-devise-cancan/issues, or fork the project and submit a pull request. If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I'll add a note to the README so that others can find your work. h2. Credits Daniel Kehoe implemented the application and wrote the tutorial. Is the app useful to you? Follow the project on Twitter: "@rails_apps":http://twitter.com/rails_apps and tweet some praise. I'd love to know you were helped out by what I've put together. h2. License h4. Public Domain Dedication This work is a compilation and derivation from other previously released works. With the exception of various included works, which may be restricted by other licenses, the author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law.

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。