zoukankan      html  css  js  c++  java
  • rails新环境

    sudo apt-get install gcc build-essential g++ libssl-dev libreadline5-dev zlib1g-dev linux-headers-generic libxml2-dev libcurl4-openssl-dev curl git-core bison zlib1g subversion autoconf libpcre3-dev iptux mysql-server-5.1 libevent-dev openssh-server imagemagick libmysql-ruby libmysqlclient-dev libsqlite3-dev

    参考了
    http://www.cnblogs.com/lexus/archive/2011/05/30/2063049.html

    install rvm
    bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
    rvm -v
    查看 rvm版本1.6.32
    rvm install 1.9.3
    rvm list
    rvm 1.9.3 --default
    rvmsudo gem install passenger
    <kbd>passenger-install-nginx-module</kbd>
    回车,选择1推荐安装
    The Nginx configuration file (/opt/nginx/conf/nginx.conf)
    must contain the correct configuration options in order for Phusion Passenger
    to function correctly.
    
    This installer has already modified the configuration file for you! The
    following configuration snippet was inserted:
    
      http {
          ...
          passenger_root /home/mlzboy/.rvm/gems/ruby-1.9.3-preview1/gems/passenger-3.0.8;
          passenger_ruby /home/mlzboy/.rvm/wrappers/ruby-1.9.3-preview1/ruby;
          ...
      }
    
    After you start Nginx, you are ready to deploy any number of Ruby on Rails
    applications on Nginx.
    
    
    
    Deploying a Ruby on Rails application: an example
    
    Suppose you have a Ruby on Rails application in /somewhere. Add a server block
    to your Nginx configuration file, set its root to /somewhere/public, and set
    'passenger_enabled on', like this:
    
       server {
          listen 80;
          server_name www.yourhost.com;
          root /somewhere/public;   # <--- be sure to point to 'public'!
          passenger_enabled on;
       }
    
    And that's it! You may also want to check the Users Guide for security and
    optimization tips and other useful information:
    
      /home/mlzboy/.rvm/gems/ruby-1.9.3-preview1/gems/passenger-3.0.8/doc/Users guide Nginx.html
    
    Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
    http://www.modrails.com/
    
    Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
    
    
    <code></code><pre><pre class="shell" style="margin-top: 0px; margin-bottom: 0px;">#gem install bundler
    gem install rails
    


    rails new xxx -JT -d mysql

    参考http://lihbobo.iteye.com/blog/1060851


    install komodo-edit
    wget http://downloads.activestate.com/Komodo/releases/6.1.2/Komodo-Edit-6.1.2-8334-linux-libcpp6-x86.tar.gz

    进入到工程目录中修改Gemfile文件,加入如下行:

    gem "jquery-rails"<br />bundle install<br />rails g jquery:install<br /><br />参考<br />
    http://www.blog.bridgeutopiaweb.com/post/how-to-use-jquery-for-rails-3/


    修改mysql编码及时区
    参考
    http://www.cnblogs.com/lexus/archive/2010/12/10/1902646.html

    安装mysql可视化工具
    sudo apt-get install mysql-query-browser mysql-admin
    sudo apt-get install gnome-do

    rake -vT
    rake -T
    rake db:create
    rake db:migrate


    生成 CRUD的代码
    rails g nifty:scaffold category name:string hidden:boolean lost:boolean


    使用以下方式来增加字段

    rails g migration add_column_to_posts lost_id:integer have_id:integer

    Generating rails migrations for adding a column

    The way to generate a migration for adding a column in rails is this:

      script<span style="color:#006600; font-weight:bold;">/</span>generate migration add_fieldname_to_tablename fieldname:<span style="color:#CC0066; font-weight:bold;">string</span>

    That will generate a file db/migrate/20080116021059_add_fieldname_to_tablename.rb that looks like this:

    <span style="color:#9966CC; font-weight:bold;">class</span> AddFieldnameToTablename <span style="color:#006600; font-weight:bold;"><</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>    add_column <span style="color:#ff3333; font-weight:bold;">:tablename</span>, <span style="color:#ff3333; font-weight:bold;">:fieldname</span>, <span style="color:#ff3333; font-weight:bold;">:string</span>  <span style="color:#9966CC; font-weight:bold;">end</span>    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>    remove_column <span style="color:#ff3333; font-weight:bold;">:tablename</span>, <span style="color:#ff3333; font-weight:bold;">:fieldname</span>  <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#9966CC; font-weight:bold;">end</span>

    Took me depressingly long to figure that out through Google. I’ve also sort of acquiesced to the notion of migrations. I still feel like it sucks that there is no centralized table definition. But it seems good for upgrading and everything once the tables are in use. So I guess migrations are a good thing.

    Failed Google searches: rails migrations, rake add column, rake add_column, rails how to add a column, script/generate migration add_column, generating migrations add_column, generate migrations


    参考
    http://erikonrails.snowedin.net/?p=125


    关于多个tag插件的选择
    http://stackoverflow.com/questions/5130657/tagging-in-rails-3

    最后使用
    gem 'acts-as-taggable-on'<br /><br />



  • 相关阅读:
    git rebase 的使用
    一分钟带你学会利用mybatis-generator自动生成代码!
    手把手带你实战下Spring的七种事务传播行为
    SpringBoot系列-整合Mybatis(注解方式)
    SpringBoot系列-整合Mybatis(XML配置方式)
    Java中打印日志,这4点很重要!
    SpringBoot集成JWT实现权限认证
    一分钟带你了解JWT认证!
    利用SpringBoot+Logback手写一个简单的链路追踪
    SpringBoot中如何优雅的读取yml配置文件?
  • 原文地址:https://www.cnblogs.com/lexus/p/2139872.html
Copyright © 2011-2022 走看看