rails笔记

24 篇文章 0 订阅

电子商务系统
restful API
问卷调查系统
考试系统
文档管理系统
爬虫系统
##############################################################
>cd D:\mysql-5.7.15-win32\bin
>mysqld -install
>mysqld --initialize

start mysql service:
>net start mysql
>net stop mysql

>mysql -u root -p 123456

#################################################################
>gem install rails -v=2.3.8
> gem sources --add http://gems.ruby-china.org/ --remove https://rubygems.org/
> gem sources -l
*** CURRENT SOURCES ***

http://gems.ruby-china.org/

> gem install rails -v=3.2.1
ERROR:  Error installing rails:
        invalid gem: package is corrupt, exception while verifying: undefined me
thod `size' for nil:NilClass (NoMethodError) in C:/Ruby22/lib/ruby/gems/2.2.0/cache/thread_safe-0.3.5.gem
=>delete the directory cache,errors will not appear when reexecute gem install

>rake db:migrate RAILS_ENV=test
>rake test:units
>rake test:functionals
>ruby -Itest test/unit/product_test.rb
>ruby -Itest test/unit/product_test.rb -n product_attributes_must_not_be_empty
>ruby -Itest test/unit/product_test.rb -n /attributes/

>rake spec
>rspec spec/models/product_spec.rb


>rails g scaffold Product title:string description:text image_url:string price:decimal
>rails g controller store index
>rails g session_migration
>rake db:migrate
>rails g scaffold cart
>rails g scaffold line_item product_id:integer cart_id:integer
>rails g migration add_quantity_to_line_item quantity:integer
>rails g migration combine_items_in_cart
>rails g scaffold order name:string address:text email:string pay_type:string
>rails g migration add_order_id_to_line_item order_id:integer
>rails g scaffold user name:string hashed_password:string salt:string
>rails g controller sessions new create destroy
>rails g controller admin index

>rails g model Document name:string file_type:string file_size:decimal parent_id:integer file_path:string absolute_path:string


>rake db:create RAILS_ENV=production
>rails s -e production
>bundle exec rake assets:precompile RAILS_ENV=production
##########################################################
mysql error 1045


1.create a txt file,contents as follow:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
the file named C:\mysql-init.txt。
2.execute=> D:\mysql-5.7.15-win32\bin\mysqld -nt --init-file=C:\mysql-init.txt
3.mysql -u root -p 123456
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
4.restart mysql service

##########################################################
MySQL修改root密码的多种方法
方法1: 用SET PASSWORD命令
  mysql -u root
  mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

方法2:用mysqladmin
  mysqladmin -u root password "newpass"
  如果root已经设置过密码,采用如下方法
  mysqladmin -u root password oldpass "newpass"

方法3: 用UPDATE直接编辑user表
  mysql -u root
  mysql> use mysql;
  mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
  mysql> FLUSH PRIVILEGES;

在丢失root密码的时候,可以这样
  mysqld_safe --skip-grant-tables&
  mysql -u root mysql
  mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
  mysql> FLUSH PRIVILEGES;
##########################################################
gem降级=>gem update --system 1.5.3
>gem install mysql2 --platform=ruby -- '--with-mysql-dir="D:\mysql-5.7.15-win32"'
>gem uninstall activerecord-mysql2-adapter
>gem install mysql2 -v=0.3.19 -- '--with-mysql-dir="D:\mysql-5.7.15-win32"'

   
gem install rspec-rails -v=2.8.0
rspec-rails:activesupport requires Ruby version >= 2.2.2
Successfully installed rspec-core-2.8.0
Successfully installed diff-lcs-1.1.3
Successfully installed rspec-expectations-2.8.0
Successfully installed rspec-mocks-2.8.0
Successfully installed rspec-2.8.0
Successfully installed rspec-rails-2.8.0
gem uninstall rspec-core diff-lcs rspec-expectations rspec-mocks rspec


recursively find the specified file in the current dir
>dir /s find jquery_ujs.js
C:\Ruby22\lib\ruby\gems\2.2.0\gems\jquery-rails-3.1.4\vendor\assets\javascripts

>findstr /s /i "last_comment" *.rb
>cd C:\cygwin\home\Administrator\Depot
strftime('%Y-%m-%d %H:%M:%S')
<%= post.updated_at.to_s(:db) %>
<%= post.updated_at.localtime.to_s(:db) %>
$ find  / -name "*.rb" |xargs grep info
$ find ./ -name "*view*" -type d

ActiveRecord::Base.logger
StoreController.logger.info "message"

>tasklist | findstr 3060
>taskkill /pid 3060 /F

/mswin|mingw/ =~ RUBY_PLATFORM
require 'securerandom'
SecureRandom.hex(10)
SecureRandom.base64(10)
SecureRandom.urlsafe_base64
SecureRandom.uuid

#########################################################
Rails 3 is not compatible with Ruby 2.2
ruby1.8.7+rails2.3.5
ruby1.9.3+rails3.0.8
ruby2.2.2p95+rails3.2.22


Ruby 2.2.0 and ActiveRecord 4.1.0 bug
Update to Rails 4.1.2
NoMethodError: undefined method `name' for nil:NilClass

C:/Ruby22/lib/ruby/gems/2.2.0/gems/activerecord3.2.1/lib/
active_record/associations/has_many_association.rb:79:
warning: circular argument reference - reflection

Changing Rails version from 3.2.15 to 3.2.22 fixed this for me.

the circular argument reference warning in activesupport
here is what i did to resolve that, i had the latest ruby and the gems are not compatible with that,
so after having a fight for nearly a day i switched to older ruby version using rvm from ruby-2.2.1
to ruby-2.0.0 ,again this is not an issue with ruby version but incompatibility with gems,try and
have good luck with that.
Active Support dependency warning when using Ruby 2.2.0
As of Rails 4, a Ruby version of at least 1.9.3 will be required
#########################################################
<%if true%>
<div>
hello
<%end%>
</div>

firefox没问题  IE会多个</div>
#########################################################
rails runner script/load_orders.rb
#########################################################
100m
500m
1km
5km
10km
25km
50km

bing:POI radius search algorithm
https://zh.scribd.com/presentation/2569355/Geo-Distance-Search-with-MySQL
Geo Distance Search with MySQL algorithm
#########################################################
>documents
name
file_type
file_size
parent_id
file_path
absolute_path
#########################################################
解压安装:
tar zxvf ruby-2.2.5.tar.gz
./configure --prefix=/usr/local --enable-shared --disable-install-doc --with-opt-dir=/usr/local/lib
make
sudo make install
ruby -v

sudo apt-get install -y build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf automake libtool  libmysqlclient-dev 
sudo apt-get install -y curl libcurl3-dev git
sudo apt-get install libmysql-ruby

在ruby的目录ext下,需要安装一下openssl。
$ cd ruby解压安装目录/ext/openssl
$ ruby extconf.rb
$ make
No rule to make target `/include/ruby.h', needed by `ossl_ns_spki.o'
#######################################################
Add this to your Makefile in ../ext/openssl (after using ruby extconf.rb):
top_srcdir = ../..  after archdir = $(rubyarchdir)
#######################################################
$ sudo make install
/usr/bin/install -c -m 0755 openssl.so /usr/local/lib/ruby/site_ruby/2.2.0/i686-linux
installing default openssl libraries

当安装gem包时,报zlib的load error,请重新进入ruby的zlib目录下重新安装。(方法同安装openssl)
$ cd ruby解压安装目录/ext/zlib
$ ruby extconf.rb
$ make
$ sudo make install

gem install rails -v=3.2.22

>mysql安装
http://dev.mysql.com/downloads/mysql/#downloads
mysql-5.7.16-linux-glibc2.5-i686.tar.gz

首先添加mysql用户组
simon@localhost$ groupadd mysql

添加mysql用户,并指定到mysql用户组
simon@localhost$ useradd -g mysql mysql

解压缩mysql-5.7.16-linux-glibc2.5-i686.tar.gz到安装目录(/usr/local/)
simon@localhost$ cd /usr/local
simon@localhost$ sudo tar zxvf /home/simon/Downloads/mysql-5.7.16-linux-glibc2.5-i686.tar.gz
simon@localhost$ ls

创建mysql软连接mysql-VERSION-OS
simon@localhost$ sudo ln -s /usr/local/mysql-5.7.16-linux-glibc2.5-i686 mysql
simon@localhost$ cd mysql
simon@localhost$ ls

设定mysql安装目录权限,设置owner为mysql
simon@localhost$ sudo chown -R mysql .
simon@localhost$ sudo chgrp -R mysql .

执行mysql系统数据库初始化脚本
sudo bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
提示mysql_install_db 命令已弃用,使用mysqld
sudo bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data 

设定data目录权限,分配给mysql用户,为了mysql程序能读写data目录下的文件
simon@localhost$ sudo chown -R root .
simon@localhost$ sudo chown -R mysql data

使用mysql帐号启动mysql应用
simon@localhost$ sudo bin/mysqld_safe --user=mysql &
cannot create /var/lib/mysql/mysqld_safe.pid: Directory nonexistent
cannot touch ‘/var/log/mysql/error.log’: No such file or directory

sudo mkdir /var/lib/mysql
sudo mkdir /var/log/mysql
sudo mkdir /var/run/mysql

/var/run/mysqld/mysqld.pid ended

设置root密码
A temporary password is generated for root@localhost: :vqfNRw&9h_E

simon@localhost$ sudo bin/mysqladmin -u root password '123456'
mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

登录mysql
simon@localhost$ bin/mysql -u root -p 

【MySQL】查看MySQL配置文件路径及相关配置
$ which mysqld
/usr/sbin/mysqld
$ /usr/sbin/mysqld --verbose --help | grep -A 1 'Default options'
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
服务器首先会读取/etc/my.cnf文件,如果发现该文件不存在,再依次尝试从后面的几个路径进行读取。

cd ~/
sudo find / -name my.cnf -type f


>The server quit without updating PID file (/usr/local/mysql/data/ubuntu.pid).
Solution 2: Remove Your MySQL Config File
If you have modified your MySQL configuration file, MySQL may not like it few versions after (MySQL is not backward compatibility friendly). It can be the problem of using an unsupported variable, or something similar. The easiest way is to remove your configuration file, and try to start the MySQL server again

Backup your MySQL configuration first.
mv /etc/mysql/my.cnf /etc/mysql/my.cnf.backup


cd /usr/local/mysql
sudo chmod -R 777 data
启动mysql
mysqld --defaults-file=/home/simon/Desktop/Depot/config/my.cnf
mysqld_safe --defaults-file=/home/simon/Desktop/Depot/config/my.cnf --user=mysql &



`require': cannot load such file -- readline (LoadError)
$ cd ruby解压安装目录/ext/readline
$ ruby extconf.rb
$ make
No rule to make target `/include/ruby.h', needed by `readline.o'.
#######################################################
Add this to your Makefile in ../ext/openssl (after using ruby extconf.rb):
top_srcdir = ../..  after archdir = $(rubyarchdir)
#######################################################
$ sudo make install

There was an error while trying to load the gem 'coffee-rails'. (Bundler::GemRequireError)
原因是缺少依赖的组件nodejs
运行sudo apt-get install nodejs 安装nodejs,再重新运行rails c即可。


在Depot外面找
sudo find / -name *.rb|xargs grep 'last_comment'

rails runner script/load_orders.rb

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值