设置bootstrapRails 实战 0x01
最近一直在学习设置bootstrap之类的问题,今天正好有机会和大家共享一下.
1. 应用 Rails Composer自动创立项目
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: admin@iwissen.com ADMIN_PASSWORD: passwd
devise.rb的config.mailer_sender改成admin_email
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 }
遇到问题都可以在官方action mailer 中找到
http://guides.rubyonrails.org/action_mailer_basics.html
这样设置就完成了
6. 为了方便和符合国人习气,把密码长度设为大于即是6(devise默认8),在devise.rb 中,修改
config.password_length = 6..128
7. rails s 开启服务器,注册新用户测试,查看console里的log
Sent mail to dragonszy@gmail.com (671ms) Date: Sun, 26 May 2013 16:28:03 +0800 From: admin@iwissen.com Reply-To: admin@iwissen.com To: dragonszy@gmail.com Message-ID: <51a1c793ba301_d983ffdb6345064853e1@MBP.local.mail> Subject: Confirmation instructions Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <p>Welcome dragonszy@gmail.com!</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>
一般邮件畸形收回或者根本没连的话,浏览器不会raise_error,因为设置了smtp连接,所以错误只能是连不上的错误,检查用户密码是否设置正确,邮箱域名是否是对的
8. 一切搞定后Github push一下
9. 自己创立几个一般用户和Admin用户试验一下,可见用Rails Composer还是省下了不少工夫的
文章结束给大家分享下程序员的一些笑话语录: 腾讯的动作好快,2010年3月5日19时28分58秒,QQ同时在线人数1亿!刚刚看到编辑发布的文章,相差才2分钟,然后连专题页面都做出来了,他们早就预料到了吧?(其实,每人赠送10Q币,轻轻松松上两亿!)
---------------------------------
原创文章 By
设置和bootstrap
---------------------------------