1. 程式人生 > >Ubuntu下建立簡單的ROR工程環境

Ubuntu下建立簡單的ROR工程環境

之前由於實際工作的需要,忙於在ubuntu下建立一個初始化工程環境,終於有機會把指令碼寫出來了,貼出來儲存一下,也分享給有需要的人看看.

1.基礎依賴環境

Ubuntu OS (12.04是個不錯的選擇)

curl -L get.rvm.io | bash -s stable source ~/.rvm/scripts/'rvm' rvm requirements

ruby-1.9.3-p125 (ruby193的語言要求更嚴格,值得試一下的)

rvm install 1.9.3-p125 mysql 5.5
sudo apt-get install mysql-server mysql-client rubygem 1.8+ (193已帶有)
rails 3.2+ (3.2.1)
gem install rails -v 3.2.1 rake 0.9.2.2
gem install rake -v 0.9.2.2

bundler 1.0.22+

gem install bundler mysql2 0.3.11
sqlite3

2.建立一個新的工程

rails new $project_name -f -d mysql -T --skip-bundle可以先設定一個工程的名字:project_name=xxxxx

3.新增工程對rvm的支援

cd $project_name touch .rvmrc echo "rvm use [email protected] --create --install" > .rvmrc rvm use [email protected]

--create --install

4.配置Gemfile並加入需要的外掛

#cd $project_name echo '# source "https://rubygems.org" source "http://ruby.taobao.org/" gem "rails", "3.2.1" # Bundle edge Rails instead: # gem "rails", :git => "git://github.com/rails/rails.git" gem "mysql2", "0.3.11" gem "sqlite3", "1.3.5" # Gems used only for assets and not required # in production environments by default. group :assets do gem "sass-rails", "~> 3.2.3" gem "coffee-rails", "~> 3.2.1" # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem "execjs", "~> 1.3.0" gem "therubyracer" gem "uglifier", ">= 1.0.3" gem "compass-rails", "~> 1.0.1" gem "bootstrap-sass", "~> 2.0.2" # compass plugin for boostrap #gem "bootstrap-rails" end # gem "haml", "~> 3.1.4" gem "haml-rails", "~> 0.3.4" gem "jquery-rails" # To use ActiveModel has_secure_password # gem "bcrypt-ruby", "~> 3.0.0" # To use Jbuilder templates for JSON # gem "jbuilder" # Use unicorn as the web server # gem "unicorn" # Deploy with Capistrano gem "capistrano" # To use debugger # gem "ruby-debug19", :require => "ruby-debug" gem "jquery-rails" gem "devise", "~> 2.0.4" gem "oauth", "~> 0.4.5" gem "oauth2" gem "cancan" #gem "userstamp" # right now not support well for rails 3.2 #gem "globalize3" gem "simple-navigation" # Menu generator gem "paperclip" # File and image upload # gem "tiny_mce" # Rich text editor, multiple language gem "tinymce-rails", "~> 3.4.9" # gem "ckeditor" # Rich text editor gem "simple_form" gem "will_paginate", "~> 3.0.pre2" #gem "rmagick", "~> 2.13.1" # Interface between Ruby and ImageMagick. #gem "rtesseract", "~> 0.0.8" # Ruby library for working with the Tesseract OCR gem "sunspot_rails", "~> 2.0.0.pre.111215" gem "sunspot_solr", "~> 2.0.0.pre.111215" gem "tlsmail", "~> 0.0.1" # enables pop or smtp via ssl/tls group :development, :test do #gem "delorean" # Travel in time with Ruby by mocking Time.now gem "simplecov", "~> 0.6.1" # instead of rcov, Code coverage tool for Ruby. gem "yard", "~> 0.7.5" gem "hamlify", "~> 1.0.0" # HTML to HAML conversion tool http://rubygems.org/gems/hamlify gem "hpricot", "~> 0.8.4" gem "ruby_parser", "~> 2.3.1" end group :test do gem "rspec-rails" gem "shoulda" gem "cucumber-rails" gem "cucumber-websteps" gem "capybara" gem "factory_girl_rails" gem "database_cleaner" gem "launchy" #gem "parallel_tests" # Speedup Test::Unit + RSpec + Cucumber # by running parallel on multiple CPUs (or cores). end' > Gemfile bundle install

5.為工程建立一個專屬於的mysql賬號

echo "grant all privileges on *.* to 'his'@'localhost' identified by 'his123';"|mysql -uroot -p$mysql_pwd 可以預先設定好mysql當前root的密碼,以保證建立成功:mysql_pwd=xxxx

6.配置工程資料庫

#cd $project_name sed -i 's/username\: root/username\: his/g' config/database.yml sed -i 's/password\:/password\: his123/g' config/database.yml

7.初始化資料庫

#cd $project_name bundle exec rake db:create

好了,可以安裝一些特殊的外掛上去了.....

8.安裝devise外掛支援(登入外掛)

bundle exec rails g devise:install # 會首先以下提示 # =============================================================================== # # Some setup you must do manually if you haven't yet: # 1. config/environments/development.rb: # config.action_mailer.default_url_options = { :host => 'localhost:3000' } # In production, :host should be set to the actual host of your application. # 2. Ensure you have defined root_url to *something* in your config/routes.rb. # root :to => "home#index" # 3. Ensure you have flash messages in app/views/layouts/application.html.erb. # <p class="notice"><%= notice %></p> # <p class="alert"><%= alert %></p> # 4. If you are deploying Rails 3.1 on Heroku, you may want to set: # config.assets.initialize_on_precompile = false # # On config/application.rb forcing your application to not access the DB # or load models when precompiling your assets. # ===============================================================================

8.1 重新修改主頁的支援

mv public\index.html public\index.html.bak bundle exec rails g controller home index sed -i 's/# root/root/g' config/routes.rb sed -i 's/welcome#index/home#index/g' config/routes.rb

8.2 新增本機郵箱主機

sed -i 's/^end/\n config\.action_mailer\.default_url_options = \{ :host => "localhost:3000" \}\n\nend/g' config/environments/development.rb #要是有域名的話,可以用上域名,如果只是本地試一下,用localhost即可.

8.3 安裝devise的模型及檢視

bundle exec rails g devise user bundle exec rails g devise:views users

8.4 將erb檔案轉換成haml檔案

touch tohaml.rb echo 'class ToHaml def initialize(path) @path = path end def convert! Dir["#{@path}/**/*.erb"].each do |file| `html2haml -rx #{file} #{file.gsub(/\.erb$/, '.haml')}` end end end path = File.join(File.dirname(__FILE__), 'app', 'views') ToHaml.new(path).convert!' > tohaml.rb ruby tohaml.rb # 注意,如果執行tohaml.rb不成功,則要考慮安裝一下haml,即: # gem install haml rm -rf app/views/**/**/*.erb

8.5 讓devise的註冊支援郵箱確認

sed -i 's/# t.string :confirmation_token/t.string :confirmation_token/g' db/migrate/*_devise_create_users.rb sed -i 's/# t.datetime :confirmed_at/t.datetime :confirmed_at/g' db/migrate/*_devise_create_users.rb sed -i 's/# t.datetime :confirmation_sent_at/t.datetime :confirmation_sent_at/g' db/migrate/*_devise_create_users.rb sed -i 's/# t.string :unconfirmed_email/t.string :unconfirmed_email/g' db/migrate/*_devise_create_users.rb sed -i 's/t.string :email/t.string :username\nt.string :email/g' db/migrate/*_devise_create_users.rb sed -i 's/:validatable/:validatable, :confirmable/g' app/models/user.rb sed -i 's/attr_accessible/attr_accessible :username,/g' app/models/user.rb # 要在development.rb配置郵箱才行, 以下是用gmail來配置,它需要tls/ssl的郵箱登入方式,163的配置相對簡單,不細說. sed -i 's/^end/\n\ require "tlsmail"\ Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)\ ActionMailer::Base.delivery_method = :smtp\ ActionMailer::Base.perform_deliveries = true\ ActionMailer::Base.smtp_settings = {\ :address => "smtp.gmail.com",\ :port => 587,\ :domain => "mails.google.com",\ :user_name => "[email protected]",\ :password => "hissys123",\ :authentication => "plain",\ :enable_starttls_auto => true}\nend/g' config/environments/development.rb

9.安裝sunspot的支援

bundle exec rails g sunspot_rails:install

10.安裝rspec的支援

bundle exec rails g rspec:install

11.安裝cucumber的支援

bundle exec rails g cucumber:install

11.1 配置一下cucumber的web_step

# referrence from https://www.relishapp.com/kucaahbe/cucumber-websteps/docs touch features/support/paths.rb #vim features/support/paths.rb echo ' ######################################################### # features/support/paths.rb module NavigationHelpers # Maps a name to a path. Used by the # # When /^I go to (.+)$/ do |page_name| # # step definition # def path_to(page_name) case page_name when /^the home\s?page$/ "/" when /the sign up page/ "/users/sign_up" when /the sign in page/ "/users/sign_in" # Add more mappings here. # Here is an example that pulls values out of the Regexp: # # when /^(.*)''s profile page$/i # user_profile_path(User.find_by_login($1)) else begin page_name =~ /^the (.*) page$/ path_components = $1.split(/\s+/) self.send(path_components.push("path").join("_").to_sym) rescue NoMethodError, ArgumentError raise "Can''t find mapping from \"#{page_name}\" to a path.\n" + "Now, go and add a mapping in #{__FILE__}" end end end end World(NavigationHelpers) #########################################################'> features/support/paths.rb touch features/support/selectors.rb #vim features/support/selectors.rb echo ' ######################################################### # features/support/selectors.rb module HtmlSelectorsHelpers # Maps a name to a selector. Used primarily by the # # When /^(.+) within (.+)$/ do |step, scope| # # step definitions # def selector_for(locator) case locator when "the page" "html > body" # Add more mappings here. # Here is an example that pulls values out of the Regexp: # # when /^the (notice|error|info) flash$/ # ".flash.#{$1}" # You can also return an array to use a different selector # type, like: # # when /the header/ # [:xpath, "//header"] # This allows you to provide a quoted selector as the scope # for "within" steps as was previously the default for the # web steps: when /^"(.+)"$/ $1 else raise "Can''t find mapping from \"#{locator}\" to a selector.\n" + "Now, go and add a mapping in #{__FILE__}" end end end World(HtmlSelectorsHelpers) #########################################################' > features/support/selectors.rb #vim features/step_definitions/web_steps.rb echo ' ######################################################### # features/step_definitions/web_steps.rb require "cucumber/websteps" #########################################################' > features/step_definitions/web_steps.rb

12.安裝simple_navigation導航欄或麵包屑

bundle exec rails g navigation_config

13.配置i18n支援

sed -i 's/# config.i18n.load_path/config.i18n.load_path/g' config/application.rb sed -i "s/'locales',/'locales', '**',/g" config/application.rb sed -i 's/# config.i18n.default_locale = :de/config.i18n.default_locale = :en/g' config/application.rb
建立其他多語言的配置資料夾,用於工程工發過程的各個型別的多語言配置

# make model support i18n, need gem globalize3 # category of locales file # - locales # - defaults # - model # - views # -users # -others # * controller should use flash[:notice] support # * model # * helper,viewer use the "t('.word')"mkdir config/locales/defaults mkdir config/models mkdir config/views mkdir config/views/users

14.配置工程支援compass & bootstrap

# 安裝compass到rails工程 bundle exec compass init rails --syntax sass # 詳細可以參考: <a href="http://compass-style.org/install/" mce_href="http://compass-style.org/install/">http://compass-style.org/install/</a> # 配置bootstrap-sass整合到compass echo "require 'bootstrap-sass'" >> config/compass.rb # 新建一個樣式sass專門引入bootstrap的配置,用@import方式 touch app/assets/stylesheets/app_bootstrap.css.sass echo '@import "bootstrap" @import "bootstrap-responsive"' > app/assets/stylesheets/app_bootstrap.css.sass # 配置js指令碼引入bootstrap的指令碼 sed -i 's/= require_tree/=# require_tree/g' app/assets/javascripts/application.js echo '// Loads all Bootstrap javascripts //= require bootstrap // Or peek any of them yourself //#= require bootstrap-transition //#= require bootstrap-alert //#= require bootstrap-modal //#= require bootstrap-dropdown //#= require bootstrap-scrollspy //#= require bootstrap-tab //#= require bootstrap-tooltip //#= require bootstrap-popover //#= require bootstrap-button //#= require bootstrap-collapse //#= require bootstrap-carousel //#= require bootstrap-typeahead' >> app/assets/javascripts/application.js

15.安裝simple_form的支援

rails g simple_form:install --bootstrap
主要外掛基本裝完,可以啟動伺服器了....

rake db:migrate rails s

Bootstrap是網格的樣式效果,支援html5及mobile, 除了它之外,像blueprint也是相類似的,而blueprint是compass支援的模式,不過沒有較好的js效果.

關於sass與scss,這些都是compass框架可以進行解析的檔案格式,兩者實現的效果完全沒有任何區別,只是兩種不一樣的程式碼模式,在工程中完全可以穿插使用,全部由compass解析. 另外還有一種是less模式,是bootstrap完全支援的,不過不能由compass解析,需要其他外掛解析支援. 可以參考: bootstrap的外掛很多個,bootstrap-sass只是其中一個,以目前的知識知道還可以實現,其他沒有測試過.

關於一些linux命令的使用

sed

sed -i 's/old_string/new_strig/g' 檔案路徑 <pre name="code" class="plain"># old_string即檔案中原來的路徑, 可以包括""號文字,或要包括單引號文字,則需要加上單綽號,如下例子:</pre># e.g1: sed -i 's/helloword/hello"world"/g' my_file.txt# e.g2: sed -i 's/helloword/hello''world''/g' my_file.txt# e.g3: sed -i "s/helloword/hello'world'/g" my_file.txt# 不過要是使用雙引號的話,則有些變數以及正則式特殊字元回失效.# 引數-i表示替換原檔案,立即生效, 不能用-e,否則無法生效

echo

# 列印變數 echo $variable # 輸出字串到檔案,並替換整個檔案 echo "context" > file # 輸出字串到檔案,並追加到檔案尾處 echo "new line" > file # 輸出整個文字塊到檔案 echo 'begin text, line 1 line 2 line 3 line "2232344" line 5 line end' >fileset variable

new_var=1 echo $new_var # output: 1 # $new_var then can be use in shell.

相關推薦

Ubuntu建立簡單ROR工程環境

之前由於實際工作的需要,忙於在ubuntu下建立一個初始化工程環境,終於有機會把指令碼寫出來了,貼出來儲存一下,也分享給有需要的人看看. 1.基礎依賴環境 Ubuntu OS (12.04是個不錯的選擇) curl -L get.rvm.io | bash

Ubuntu建立python虛擬開發環境

1.升級python包管理工具pip[非必須] pip install --upgrade pip2.python虛擬環境安裝 sudo apt-get install python-virtualenv sudo pip install virtualenvwrapper

Ubuntu建立Python虛擬環境的方法!

Ubuntu下建立Python虛擬環境的方法!## 建立虛擬環境有兩個很方便的辦法: 使用virtualenv 使用python3-venv 使用virtualenv 首先先安裝: pip install virtualenv 建立虛擬環境的過程

Linux(Ubuntu)搭建ASP.NET Core環境

代碼 win ner tps tool 環境 pan test deb 今天來學習一下ASP.NET Core 運行在Ubuntu中。無需安裝mono 。 環境 Ubuntu 14.04.4 LTS 服務器版 全新安裝系統。 下載地址:http://mirrors.n

Eclipse建立簡單JNI程序實現返回double類型

package 技術分享 png 環境變量path post 磁盤 jni 函數 height 在Eclipse下生成時要註意,由於通常是在package裏面添加類,而非像單獨建立工程時獨立添加,所以,在編譯的時候,都需要進入包所在的文件夾, javac 包名.類名 這樣的

可能是Windows簡單的Java環境安裝指南

因此 打開 png roc ado 開源 window environ 就是 1. 簡介 JDK : Java SE Development Kit Java開發工具 JRE : Java Runtime Environment Java運行環境 如果要從事Java

ubuntu搭建php後臺開發環境——ubuntu16.04+apach2.4.18+php7.0.28+mysql+PhpStorm

在ubuntu下搭建php後臺開發環境——ubuntu16.04+apache2.4.18+php7.0.28+mysql+PhpStorm 此篇文章是記錄自己在搭建php後臺開發環境的流程,適合新手。 名詞解釋 ubuntu——一款基於linux核心的作業系統,對標Window

Ubuntueclipse編譯c/c++環境配置

1,下載帶CDT外掛的eclipse版本        sudo apt-get install eclipse-cdt 2,安裝後啟動建立c++專案,然後在/project/properties下修改相關配置如下圖。不然會出現

在虛擬機器Ubuntu進行簡單的ko驅動編寫問題處理

主要就是編寫了驅動模組Helloko(hello.c 、Makefile) & 測試應用程式(hellotest.c) hello.c:   makefile: hellotest.c: step1: make   先生成k

嘗試IAR建立stm32新工程及bootloader

之前在iar下開發都是在官方例程或網路中下載的例程,開發時IAR直接跳入main中執行c程式碼,最近想建立個新的stm32工程來寫一些彙編檔案瞭解下CM3彙編指令,於是痛苦摸索了很多天。 起初建立了IAR新工程,使用的stm32f103x,加入了官方提供的iar工程檔案:startup.s,原本

ubuntu pycharm 構建ROS程式設計環境

1    安裝和破解pycharm 1.1    解壓下載好的pycharm包 1.2    下載破解檔案JetbrainsCrack-3.1-release-enc.jar link:http://idea.lanyus.

ubuntudocker簡單安裝mysql

一、簡介   Docker是DotCloud開源的、可以將任何應用包裝在Linux container中執行的工具。 二、ubuntu快速安裝,具體安裝可以參考官網:https://docs.docker.com/install/ sudo apt install -y docker.io

ubuntu建立navicat圖示

  sudo vim /usr/share/applicationsnavicat.desktop 檔案寫入如下內容,Exec,Icon填寫執行檔案和圖示的地址,需要根據自己實際情況修改,若無圖示自己官網下一個最好     1 [Desktop Entry]

ubuntudocker簡單安裝rabbitmq ubuntudocker簡單安裝mysql

一、docker安裝只需要幾步即可,安裝docker和切換映象源見:ubuntu下docker簡單安裝mysql # 下載映象 docker pull rabbitmq # 啟動映象 docker run --name rabbitmq -p 15672:15672 -p 5672:5672 -d

ubuntu建立 檔案 快捷命令開啟方式

以安裝包 安裝sublime 建立快捷命令為例 1、mv /sublime_test3/sublime_text /opt  將整個解壓好的包 傳送到/opt 目錄下(sublime_text為程式開啟入口) 2、sudo ln -s /opt/sublime_text_

ubuntu建立資料夾快捷方式

title: ubuntu下建立資料夾快捷方式 toc: false date: 2018-09-01 17:22:28 categories: methods tags: ubuntu 快捷方式 sudo ln -sT [srcDir] [dstDir/name]

Ubuntu搭建Appium+python自動化環境記錄及遇到的錯誤記錄

     系統:Ubuntu 18.04.1 LTS   64位 搭建環境前準備     1.JDK 8安裝     2.android-sdk_r24.3.4-linux  

Ubuntu建立XFS檔案系統的LVM

[email protected]:~# fdisk -lDisk /dev/sdb: 605 GiB, 649613803520 bytes, 1268776960 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/p

配置整理——Ubuntu配置Java Spring開發環境

Spring是一個基於Java的開源框架,最近需要使用它來完成一個專案,現在將在Ubuntu下的開發環境配置過程記錄一遍。 安裝JDK 在Linux下,除了常用的Oracle的JDK外,還有一個OpenJDK可以選擇。一般情況下使用哪一個都沒有太大的問題,但考慮到通用性移

Ubuntu建立eclipse的桌面快捷方式

1:在/usr/share/applications/建立.desktop檔案 vim /usr/share/applications/eclipse.desktop 2:輸入相應的資訊 #########=====如下吉祥是必須配置的======