Ruby on Rails 开发手记

Ruby on Rails 开发手记

Rails 安装问题

1.安装Ubuntu 18.04LTS
2.安装 Ruby-full --注意环境权限
3.安装 Rails

gem install rails -v 5.2.4.4

推荐参考。。。反正能找到。

4. 安装Gem包问题:sudo rails new project

遇到问题,参考这个解决:安装git 可解决。

http://ask.sov5.cn/q/NdCbBd4VZZ

类似的很多都是安装Gem包解决。

5.权限不够问题1:rake permission denied
6.权限不够问题2:类似的还有bundle install There was an error while trying to write to…

参考https://blog.csdn.net/sunnylive863/article/details/84196412

sudo chmod -R 777 /Users/you_user_name/.bundle/

脚手架网站搭建问题–菜单作业

1.实用技巧1:数据库还原https://www.itranslater.com/qa/details/2583741022169728000
rake db:migrate VERSION=0
rake db:migrate
2.数据库冗余报错,比如有两个列标头重复。

这个需要注意migrate文件中,create文件和add文件,有一样的作用。

比如create recipes中有两个 string 量,一个叫title, 一个叫instruction

这时候如果再有AddInstructionToRecipes, 就是在原有instruction Colum的时候,添加了同名列。

3.加入新属性后,新属性没有在数据库中正常添加、更新。

已知数据库从特定form 的recipe string 读取信息更新。那么这个form在哪里呢?

在controllers/recipes_controllers.rb 中有对 recipe_params 的 定义:

def recipe_params
	params.require(:recipe).permit(:title, :category_id, :instruction)
end

•ActionRecord#update方法需要显式声明允许更新的param参数

•在这里,就是需要允许category_id参数

•修改为:
在这里插入图片描述

GitLab 使用问题

1. yml格式问题

主要是需要“- ”

例子:

test:
  stage: test
  script:
    - cd cookbook3
    - bundle install
    - rails db:migrate RAILS_ENV=test
    - rails test
  only:
    - cookbook3

deploy:
  stage: deploy
  script:
    - sudo apt-get install -y rsync
    - puma-stop 3000
    - rsync -arv --delete ./cookbook3 ~
    - cd ~/cookbook3
    - bundle install
    - rails db:migrate
    - nohup rails server -d -b 0.0.0.0 -p 3000 &
  only:    - cookbook3 

你可能感兴趣的:(Ruby,ruby,on,rails)