`

rails笔记

 
阅读更多

电子商务系统
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

 

分享到:
评论

相关推荐

    Ruby_on_Rails笔记

    在《Ruby on Rails笔记》中,作者陈刚分享了他在学习Ruby on Rails过程中的经验与心得。这份笔记不仅包含了作者的学习历程和个人体会,还汇集了他在学习过程中遇到的问题及其解决方案。作者提到,“读不如做,做不如...

    Ruby_On_Rails笔记

    综上所述,Ruby on Rails的笔记内容涵盖了从安装Rails环境到创建和运行一个简单的Rails项目的基础知识,这些内容对于初学者来说是学习Rails框架的极好入门材料。通过对这些知识点的学习,初学者可以快速了解Rails的...

    ruby on rails 笔记(陈刚)

    从给定的文件信息来看,这份文档是陈刚关于Ruby on Rails的学习笔记,旨在帮助初学者更好地理解并掌握Ruby on Rails这一流行的Web开发框架。以下是对文档中提及的关键知识点的详细解析: ### 安装与配置 #### Ruby...

    web敏捷开发rails笔记

    ### Web敏捷开发与Rails实践详解 #### 一、Rails简介及环境搭建 Rails是一个用于Web开发的开源框架,它基于Ruby语言,强调简洁性、生产力和开发者效率。Rails通过约定优于配置的原则,使得开发者能够快速地搭建Web...

    Ruby-on-Rails-101:Ruby on Rails 笔记摘自 WDI HKV 和其他来源。 比如,lynda的在线Rails教程

    本笔记摘录自WDI HKV以及lynda.com的在线Rails教程,旨在提供一个全面且深入的学习指南。 ### 1. **基础概念** - **MVC架构**:Rails采用Model-View-Controller(MVC)设计模式,将业务逻辑(Model)、用户界面...

    rails查询学习笔记

    标题 "rails查询学习笔记" 涉及的是Ruby on Rails框架中的数据库查询技术。Ruby on Rails,简称Rails,是一款基于Ruby语言的开源Web应用程序框架,它遵循MVC(模型-视图-控制器)架构模式,使得开发Web应用更加高效...

    rails 入门详细笔记

    rails官网入门笔记的翻译,非常不错的rubyonrails入门教程!

    rails _sunspot 学习笔记

    1. **Ruby on Rails 3**:本文档主要针对 Rails 3 版本。 2. **Solr**:全文检索引擎,Sunspot 依赖于 Solr 来实现其功能。 3. **Sunspot gem**:Sunspot 的核心 gem,通过这个 gem 可以轻松配置和使用 Sunspot 功能...

    rails_入门详细笔记(官网翻译).

    ### Rails 入门详细笔记知识点解析 #### 一、环境搭建 在开始使用 Rails 进行开发之前,首先需要确保你的开发环境满足以下条件: - **Ruby 版本**:推荐使用 Ruby 1.9.2 或更高版本。这是因为早期版本如 1.8.7 ...

    Ruby On Rails上手笔记(安装使用全过程)

    有机会再试一试Rails了,只是原来接触的是2,现在已然变成了4,似乎现在的安装比原来会快些。。 Rails 4 安装 针对于安装了RVM 代码如下:gem install rails没有的话应该这样: 代码如下:sudo gem install rails安装...

    ruby on rails环境搭建学习笔记;passenger+nginx环境配置

    ### Ruby on Rails 环境搭建与 Passenger+Nginx 配置详解 #### 一、Ruby on Rails 开发环境搭建 在进行 Ruby on Rails 的开发之前,首先需要完成一系列的基础软件安装工作,包括但不限于 Ruby 语言环境、Rails ...

    ruby on rails 实践

    Ruby on Rails是一种流行的开源网站开发框架,它利用Ruby语言,遵循MVC(模型-视图-控制器)设计原则,用于快速开发数据库驱动的动态网站。本书《Ruby on Rails 实践》是一本指南,旨在向读者介绍Ruby on Rails框架...

    Ruby on Rails心得

    陈刚撰写的《Ruby on Rails心得_V0.1》是一份非常宝贵的资料,旨在记录作者在学习Ruby on Rails过程中的所见所得,包括读书笔记、心得体会、自创教程及一些常见问题的解决方案。作者通过写作这种方式不仅加深了对...

    ruby on rails入门

    - **Notes 表**:创建 Notes 表来管理用户的笔记。 - **使用 Model 维护关联**:利用 ActiveRecord 的关联功能来处理表之间的关系。 - **Session 变量**:使用 Session 变量来保存用户的数据,以便在不同页面之间...

    Ruby On Rails开发从头来系列教程(chm)

    一边读着《Agile Web Development with Rails》的英文电子版,一边写随笔,并且尽量写的简单明了些,对于具体的细节概念倒没有做深入的研究,所以,这一系列也是《Agile Web Development with Rails》的读书笔记...

    rails-style-guide:社区驱动的Ruby on Rails样式指南

    Rails样式指南榜样很重要。 -军官Alex J. Murphy / RoboCop 小费您可以在找到本指南的精美版本,并对其导航进行了改进。 本指南的目的是为Ruby on Rails 4开发提供一组最佳... 笔记这里的一些建议仅适用于Rails 4.0+。

    Rail笔记

    从给定的文件信息来看,这份笔记主要围绕Ruby on Rails(简称Rails)这一热门的Web应用框架进行深入探讨。Rails是一种使用Ruby编程语言构建的全栈Web开发框架,以其高效、简洁、优雅的设计哲学而闻名,深受广大...

Global site tag (gtag.js) - Google Analytics