本练习参照:《简学互动》chenge 编写的实例教程
Hello World教程:http://jianshu.io/p/a625732993a9
Register教程:http://jianshu.io/p/69ad9fc5f936
简学互动:http://jianxue21.sinaapp.com/
一、环境配置
$ ruby -v
~> 2.2.0
$ rails -v
~> 4.1.0
$ sqlite3 -version
~> 3.8
sqlite3安装可参考:http://mac-dev-env.patrickbougie.com/sqlite/
二、建表
详见chenge的Register教程:http://jianshu.io/p/69ad9fc5f936
1. `rails g migration CreateUsers`
![](http://ww1.sinaimg.cn/large/7fafc03bgw1efldhozvrzj20bz00ymx3.jpg)
2. 修改 db/migrate/20140419142532_create_users.rb
![](http://ww3.sinaimg.cn/large/7fafc03bgw1efldmvcli1j20l908xjs4.jpg)
3. rake db:migrate
![](http://ww1.sinaimg.cn/large/7fafc03bgw1efldp78252j20b9020aa6.jpg)
三、准备Controller和Model
详见chenge的Register教程:http://jianshu.io/p/69ad9fc5f936
Controller
![](http://ww3.sinaimg.cn/large/7fafc03bgw1efldthm0q2j20mv08wwfi.jpg)
Model
![](http://ww3.sinaimg.cn/large/7fafc03bgw1efldwyhc15j20ij08w3yw.jpg)
四、Views
详见chenge的Register教程:http://jianshu.io/p/69ad9fc5f936
主要试图为 register_form.erb,用来提交注册用的数据。
![](http://ww2.sinaimg.cn/large/7fafc03bgw1efle0j5l7ej20mw09jq4f.jpg)
![](http://ww1.sinaimg.cn/large/7fafc03bgw1efle3lqd8zj20d0051aaf.jpg)
五、测试
详见chenge的Register教程:http://jianshu.io/p/69ad9fc5f936
$ cd your_path/register
$ sqlite3 db/development.sqlite3
$ select * from users;
![](http://ww4.sinaimg.cn/large/7fafc03bgw1efleaz3626j209n02x74e.jpg)
或者使用数据库软件
![](http://ww4.sinaimg.cn/large/7fafc03bgw1eflecmx3r2j20fa03rwet.jpg)
六、遇到的问题
(并不是仅仅出现在rails 4.1.0中)
![](http://ww2.sinaimg.cn/large/7fafc03bgw1eflde7esumj20bw06l0t3.jpg)
google的解决方法:在application_controller.rb中添加
skip_before_filter :verify_authenticity_token
![](http://ww3.sinaimg.cn/large/7fafc03bgw1eflexp8x4zj20tj04zwfh.jpg)
问题说明:
按照教程完成代码后,测试,在注册界面输入完用户名和密码后,点击提交按钮,报出:ActionController::InvalidAuthenticityToken
查看log/development.log
![](http://ww2.sinaimg.cn/large/7fafc03bgw1eflem93qxkj20ma02ugm6.jpg)
目前还不明白是什么原因。提供如下三个链接,里面有遇到类似问题的同学在讨论。
以上问题,还请各位路过的大牛给予讲解!感谢!