发布于 2016-02-01 06:19:01 | 117 次阅读 | 评论: 0 | 来源: 网友投递
Ruby on Rails 开源网络应用框架
Ruby on Rails 是一个用于开发数据库驱动的网络应用程序的完整框架。Rails基于MVC(模型- 视图- 控制器)设计模式。从视图中的Ajax应用,到控制器中的访问请求和反馈,到封装数据库的模型,Rails 为你提供一个纯Ruby的开发环境。发布网站时,你只需要一个数据库和一个网络服务器即可。
有机会再试一试Rails了,只是原来接触的是2,现在已然变成了4,似乎现在的安装比原来会快些。。
Rails 4 安装
针对于安装了RVM
gem install rails
sudo gem install rails
curl -L https://get.rvm.io | bash -s stable
rails -vRails 4.0.3
Ruby版本
We recommend Ruby 2.1.0 for use with Rails. We stopped supporting Ruby 1.8.x after Rails 3.2. Ruby 1.9.2+ will be supported until Rails 5.
官方推荐用2.1.0. 也就是最新版本
安装SQLite
似乎这就是诸如Django、Rails这类对于轻量级网站的数据库要求。
如果是mac os
brew install sqlite3
sudo zypper install sqlite3
可以直接用rails生成
$rails new hello
create create README.rdoc create Rakefile create config.ru create .gitignore create Gemfile create app create app/assets/javascripts/application.js create app/assets/stylesheets/application.css create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/views/layouts/application.html.erb create app/assets/images/.keep create app/mailers/.keep create app/models/.keep create app/controllers/concerns/.keep create app/models/concerns/.keep create bin create bin/bundle create bin/rails create bin/rake create config create config/routes.rb create config/application.rb create config/environment.rb create config/environments create config/environments/development.rb create config/environments/production.rb create config/environments/test.rb create config/initializers create config/initializers/backtrace_silencers.rb create config/initializers/filter_parameter_logging.rb create config/initializers/inflections.rb create config/initializers/mime_types.rb create config/initializers/secret_token.rb create config/initializers/session_store.rb create config/initializers/wrap_parameters.rb create config/locales create config/locales/en.yml create config/boot.rb create config/database.yml create db create db/seeds.rb create lib create lib/tasks create lib/tasks/.keep create lib/assets create lib/assets/.keep create log create log/.keep create public create public/404.html create public/422.html create public/500.html create public/favicon.ico create public/robots.txt create test/fixtures create test/fixtures/.keep create test/controllers create test/controllers/.keep create test/mailers create test/mailers/.keep create test/models create test/models/.keep create test/helpers create test/helpers/.keep create test/integration create test/integration/.keep create test/test_helper.rb create tmp/cache create tmp/cache/assets create vendor/assets/javascripts create vendor/assets/javascripts/.keep create vendor/assets/stylesheets create vendor/assets/stylesheets/.keeprun bundle install
Fetching gem metadata from https://rubygems.org/.......... Fetching additional metadata from https://rubygems.org/.. Resolving dependencies... Using rake (10.3.1) Using i18n (0.6.9) Using minitest (4.7.5) Using multi_json (1.9.2) Using thread_safe (0.3.3) Using tzinfo (0.3.39) Using activesupport (4.0.3) Using builder (3.1.4) Using erubis (2.7.0) Using rack (1.5.2) Using rack-test (0.6.2) Using actionpack (4.0.3) Using mime-types (1.25.1) Using polyglot (0.3.4) Using treetop (1.4.15) Using mail (2.5.4) Using actionmailer (4.0.3) Using activemodel (4.0.3) Using activerecord-deprecated_finders (1.0.3) Using arel (4.0.2) Using activerecord (4.0.3) Using bundler (1.5.3) Using coffee-script-source (1.7.0) Using execjs (2.0.2) Using coffee-script (2.2.0) Using thor (0.19.1) Using railties (4.0.3) Using coffee-rails (4.0.1) Using hike (1.2.3) Using jbuilder (1.5.3) Using jquery-rails (3.1.0) Using json (1.8.1) Using tilt (1.4.1) Using sprockets (2.11.0) Using sprockets-rails (2.0.1) Using rails (4.0.3) Using rdoc (4.1.1) Using sass (3.2.19) Using sass-rails (4.0.3) Using sdoc (0.4.0) Using sqlite3 (1.3.9) Using turbolinks (2.2.2) Using uglifier (2.5.0) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
运行Rails
$rails server
创建controller
如官方指南所说http://guides.rubyonrails.org/getting_started.html
执行命令:
$rails generate controller welcome index
create app/controllers/welcome_controller.rb route get "welcome/index" invoke erb create app/views/welcome create app/views/welcome/index.html.erb invoke test_unit create test/controllers/welcome_controller_test.rb invoke helper create app/helpers/welcome_helper.rb invoke test_unit create test/helpers/welcome_helper_test.rb invoke assets invoke coffee create app/assets/javascripts/welcome.js.coffee invoke scss create app/assets/stylesheets/welcome.css.scss
在config/routes.rb添加默认页面
root 'welcome#index'
rails server
Welcome#index
Find me in app/views/welcome/index.html.erb
一切来得很快,很突然。