`
wudixiaotie
  • 浏览: 132412 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
JavaScript: var now = new Date(); var monday = now; monday.setDate(now.getDate() - now.getDay() + 1); monday_date = monday.getFullYear() + "-" + monday.getMonth() + "-" + monday.getDate(); now = new Date(); var sunday = new Date(); sunday.setDate(now.getDate() - now.getD ...

Draper的用法

  当你的ror模板中有许多的地方都有重复的代码的时候,就应该考虑重构了,例如提取重复的表单,但是这种重复的表单毕竟是少数。很多情况是表单之间有微小的差距,这样提取的模板就会逻辑极度复杂,不利于代码的维护。这时候我们就应该考虑Draper了。这真是一个神级的gem。对我用处真的很大。It's amazing!!!   今天先写到这,明天继续。 仔细研究了一下draper,非常不幸,他并没有我想象中的那么美好。 一定要用的话 感觉花费的代价和获得的便利不是很让人满意。所以就放弃了在me2中应用这个gem。

faye

    博客分类:
  • ruby
http://railscasts.com/episodes/260-messaging-with-faye?view=asciicast
mE2: https://me-2.herokuapp.comcode: https://github.com/wudixiaotie/mE2  
使用rvm来快速部署nginx+passenger *首先安装passenger gem install passenger 然后使用passenger-install-nginx-module 来安装nginx和部署。 因为这一步需要root权限(因为要编译nginx)可以用rvmsudo这个东西。(这个东西真是个好东西) rvmsudo passenger-install-nginx-module 然后会让你选择是下载nginx源码自动编译安装,还是自己选择nginx源码位置。

Rails flash

flash是个hash用于在两个actions间传递临时数据,flash中存放的所有数据会在紧接着的下一个action调用后清除。一般用于传递提示和错误消息。 class PostsController < ActionController::Base def create # save post flash[:notice] = "Post successfully created" redirect_to @post end def show # doesn't need to assign the ...
1.Heroku 使用 PostgreSQL(发音 post-gres-cue-ell,经常简称 Postgres),所以我们要把 pg 加入生产组,Rails 才能和 PostgreSQL 通信: group :production do gem 'pg', '0.15.1' end   2.login heroku $ heroku login   3.heroku create $ cd your app $ heroku login   4.through git push your app to heroku: $ git push heroku ma ...

Rails常用命令

test环境数据库签移: $ rake db:migrate RAILS_ENV=test   $ rake test:prepare 启动server的环境变量: $ rails server --environment production 改变控制台环境: $ rails console test  
唯一性验证无法真正保证唯一性。 validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false }  不会吧,哪里出了问题呢?下面我来解释一下。 Alice 用 alice@wonderland.com 注册; Alice 不小心按了两次提交按钮,连续发送了两次请求; 然后就会发生下面的事情:请求 1 在内存中新建了一个用户对 ...
 如果在Heroku.com的网站上重命名app,不会自动同步到开发机的*.git文件中,需要手工重命名。 $ heroku apps:rename newname  newname是新的app名字。可以参考  

Rails Project Init

 1.rspec $ rails generate rspec:install  2.guard $ bundle exec guard init rspec  3.加入默认 Guardfile 的代码,注意顶部的 require require 'active_support/inflector' guard 'rspec', all_after_pass: false do . . . watch('config/routes.rb') # Custom Rails Tutorial specs watch(%r{^app/contro ...
class Base #定义inherited这个hook,当Base类被model类继承的时候就执行 def self.inherited(model) arr_attr_name = %w{id title body create_by}#这里可以取得model的名字,再到数据库中去查询 arr_attr_name.each do |attr_name| model.class_eval {attr_accessor attr_name}#给model类添加方法 end end end class Post < Base end ...
 1.安装RVM: $ curl -sSL https://get.rvm.io | bash -s  2.安装依赖: $ rvm requirements  3.安装ruby: $ rvm install 2.0.0  4.修改终端启动脚本: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*  看看 ~/.bashrc 里面有没有这句, ...

ubuntu 初始化

PS1 subl .bashrc PS1='\n${debian_chroot:+($debian_chroot)}\342\224\214\[\e[01;32m\][\[\e[33m\]\u\[\e[31m\]@\[\e[34m\]\h\[\e[37m\]:\[\e[36m\]\w\[\e[32m\]]\[\e[01;m\]\n\342\224\224\[\e[01;36m\]$\[\e[m\] '     RVM每次新开终端RVM脚本没载入:RVM is not a function   [[ -s "$HOME/.rvm/scripts/rvm" ]] ...

Mysql用户

1.mysql的用户表所在的数据库名称也叫mysql,要修改首先要用root用户登录myql才能使用mysql库: use mysql;  2.然后显示所有用户: select user, host, password from user;  3.然后更新你要更新的信息,最后重置权限: flush privileges;  4.然后你就可以用新密码登录了。
Global site tag (gtag.js) - Google Analytics