ITeye博客

日子头上一把刀--DRY&&KISS

wudixiaotie · 共 155 篇文章

查找当前日期所在周的周一的日期

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.getDay() + 7); monday_date = sun…

2014-03-19 15:52 · Rails · JavaScript · 评论(0) · Rails · JavaScript

Draper的用法

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

2014-03-16 19:07 · Rails · ruby · 评论(0) · Rails

faye

http://railscasts.com/episodes/260-messaging-with-faye?view=asciicast

2014-03-13 17:19 · ruby · 评论(0)

我的heroku项目,欢迎大家访问

mE2: https://me-2.herokuapp.com code: https://github.com/wudixiaotie/mE2

2014-03-13 11:28 · Rails · 评论(0) · Github · Heroku

使用rvm来快速部署nginx+passenger

使用rvm来快速部署nginx+passenger *首先安装passenger gem install passenger 然后使用passenger-install-nginx-module 来安装nginx和部署。 因为这一步需要root权限(因为要编译nginx)可以用rvmsudo这个东西。(这个东西真是个好东西) rvmsudo passenger-install-nginx-module 然后会让你选择是下载nginx源码自动编译安装,还是自己选择nginx源码位置。 选择nginx手动安装的可以添加别的编译参数,方便自定义编译nginx。 然后一路下载安装。默认的安装位置为/…

2014-03-12 13:12 · Linux · 评论(0) · Ubuntu

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 flash notice to the template, that's done a…

2014-03-02 21:50 · Rails · 评论(0) · Flash · Rails

在heroku上部署Rails和遇到的问题

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 master 5.change app na…

2014-03-01 12:49 · Rails · 评论(0) · Rails

Rails常用命令

test环境数据库签移: $ rake db:migrate RAILS_ENV=test $ rake test:prepare 启动server的环境变量: $ rails server --environment production 改变控制台环境: $ rails console test

2014-02-28 16:32 · Rails · 评论(0) · Rails

验证唯一性的不足

唯一性验证无法真正保证唯一性。 validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: { case_sensitive: false } 不会吧,哪里出了问题呢?下面我来解释一下。 Alice 用 alice@wonderland.com 注册; Alice 不小心按了两次提交按钮,连续发送了两次请求; 然后就会发生下面的事情:请求 1 在内存中新建了一个用户对象,通过验证;请求 2 也一样。请求 1 创建的用户存入了数据库,请求 2 创建的用户也存入了数据库。 结果是,尽管有唯一…

2014-02-28 15:50 · Rails · 评论(0) · Rails

重命名Heroku的app

如果在Heroku.com的网站上重命名app,不会自动同步到开发机的*.git文件中,需要手工重命名。 $ heroku apps:rename newname newname是新的app名字。可以参考

2014-02-27 18:40 · Rails · 评论(0) · Rails

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/controllers/(.+)_(controller)\.rb$}…

2014-02-26 00:56 · Rails · 评论(0) · Rails

Rails里ActiveRecord里字段自动生成的实现。

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 post = Post.new post.id = 1 p…

2014-02-24 21:21 · Rails · 评论(0) · Rails · ActiveRecord

ubuntu13.10 Rails环境

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 里面有没有这句,有的话直接把这个 ~/.bash_profile 删掉 没有的话,把这句添加到 ~/…

2014-02-22 16:21 · Rails · Linux · 评论(0) · Ubuntu · Rails

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" ]] && source "$HOME/.rvm/…

2014-02-22 13:19 · Linux · 评论(0) · Ubuntu · PS1

Mysql用户

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

2014-02-16 12:13 · mysql · 评论(0) · MySQL