rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
Rails Composer是Rails App Composer的简化版本,适合新手使用,教程在这儿https://github.com/RailsApps/rails-composer/
2. 选择1)
I want to build my own application
因为1)选项可以自行设置所有配置,下面是我选择的
question Install an example application? 1) 1) I want to build my own application 2) membership/subscription/saas (Stripe or Recurly) 3) rails-prelaunch-signup 4) rails3-bootstrap-devise-cancan 5) rails3-devise-rspec-cucumber 6) rails3-mongoid-devise 7) rails3-mongoid-omniauth 8) rails3-subdomains question Web server for development? 1) 1) WEBrick (default) 2) Thin 3) Unicorn 4) Puma question Web server for production? 3) 1) Same as development 2) Thin 3) Unicorn 4) Puma question Database used in development? 3)注意若选择非SQLite,需要开启相应数据库server 1) SQLite 2) PostgreSQL 3) MySQL 4) MongoDB question Template engine? 1) 1) ERB 2) Haml 3) Slim (experimental) question Unit testing? 2) 1) Test::Unit 2) RSpec question Integration testing? 2) 1) None 2) RSpec with Capybara 3) Cucumber with Capybara 4) Turnip with Capybara question Fixture replacement? 2) 1) None 2) Factory Girl 3) Machinist question Front-end framework? 2)选Zurb貌似会遇到一些问题,这里选Bootstrap 1) None 2) Twitter Bootstrap 3) Zurb Foundation 4) Skeleton 5) Just normalize CSS for consistent styling question Twitter Bootstrap version? 2) 1) Twitter Bootstrap (Less) 2) Twitter Bootstrap (Sass) question Add support for sending email? 3)这里是发邮件服务,如果使用Gmail发邮件则选Gmail,我用的是网易企业邮箱,所以选择SMTP,需要后续配置 1) None 2) Gmail 3) SMTP 4) SendGrid 5) Mandrill question Authentication? 2)先用devise,后续可自行添加OmniAuth 1) None 2) Devise 3) OmniAuth question Devise modules? 3)Confirmable是需要邮件认证的,本地测试需配置邮件发送,当然也可以手动修改数据表或controller 1) Devise with default modules 2) Devise with Confirmable module 3) Devise with Confirmable and Invitable modules question Authorization? 2) 1) None 2) CanCan with Rolify question Use a form builder gem? 2) 1) None 2) SimpleForm question Install a starter app? 4) 1) None 2) Home Page 3) Home Page, User Accounts 4) Home Page, User Accounts, Admin Dashboard extras Add 'therubyracer' JavaScript runtime (for Linux users without node.js)? (y/n) extras Set a robots.txt file to ban spiders? (y/n) n extras Create a project-specific rvm gemset and .rvmrc? (y/n) n extras Create a GitHub repository? (y/n) n
这里先不创建Github,以后手动添加BitBucket,Gitlab均可
3. 基本程序创建完成
上传到Github或其他
4. 看一下目录结构,默认第一个User是 First User,邮箱密码在application.yml中有,创建新的User我们这里因为选择了Confirmable,需要发邮件认证
5. 配置一下邮件发送,我这里用的是网易企业邮箱
Application.yml的 ADMIN_EMAIL和ADMIN_PASSWORD改成使用邮箱服务的账号密码
# 用admin_email发送确认邮件 devise.rb development.rb production.rb ADMIN_NAME: iwissen ADMIN_EMAIL: [email protected] ADMIN_PASSWORD: passwd
config.mailer_sender = ENV['ADMIN_EMAIL']
development.rb 和 production.rb 添加action_mailer的smtp_settings
config.action_mailer.smtp_settings = { :address => 'smtp.ym.163.com', :port => 25, :domain => 'iwissen.com', :user_name => ENV['ADMIN_EMAIL'], :password => ENV['ADMIN_PASSWORD'], :authentication => :plain }
注意development.rb 的 config.action_mailer.perform_deliveries = true, config.action_mailer.raise_delivery_errors = true 而 production.rb 的 errors设成false
当然,使用SettingLogic gem的可以用Setting.xxx,也可以直接上字符串
这里附上Gmail的设置
config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :user_name => 'poshboytl', :password => ENV['GMAIL_PASS'], :authentication => 'plain', :enable_starttls_auto => true }
这样设置就完成了
6. 为了方便和符合国人习惯,把密码长度设为大于等于6(devise默认8),在devise.rb 中,修改
config.password_length = 6..128
Sent mail to [email protected] (671ms) Date: Sun, 26 May 2013 16:28:03 +0800 From: [email protected] Reply-To: [email protected] To: [email protected] Message-ID: <[email protected]> Subject: Confirmation instructions Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <p>Welcome [email protected]!</p> <p>You can confirm your account email through the link below:</p> <p><a href="http://localhost:3000/users/confirmation?confirmation_token=2suzwouTz3NoqbzRKsdU">Confirm my account</a></p>
8. 一切搞定后Github push一下
9. 自己创建几个一般用户和Admin用户试验一下,可见用Rails Composer还是省下了不少功夫的