vkill'blog

“技术本身没有太多价值,掌握了新的思考方式才是真的收获”
Pages: 10/34 First page Previous page 5 6 7 8 9 10 11 12 13 14 Next page Final page [ View by Articles | List ]
关于n秒后跳转google上很多文章,讲的很详细了
这里主要还是使用meta来实现
直接照下面这样写就可以了

render :text=>'<meta http-equiv="refresh" content="3; url=/welcome"> 3s refresh'



如果需要这里我们写个helper来做这个事情
类别:ruby & rails | Tags: , , , | 0 条评论, 1273 次阅读
Jul
28
2010
源自此文 http://www.javaeye.com/topic/720086
比如需要修改User 和 Class 这两个model的 primary_key ,如果不用 抽象类 的话那就需要修改所有model,而使用 抽象类 的话只需要在修改抽象类的属性 abstract_class 值为true就好了,具体如下所示

#不使用抽象类
class User < ActiveRecord::Base
  set_primary_key "name"
end
class Class < ActiveRecord::Base
  set_primary_key "name"
end


#使用抽象类
class AbstractModel < ActiveRecord::Base
  set_primary_key "name"
  self.abstract_class = true
end
class User < AbstractModel
end
class Class < AbstractModel
end

类别:ruby & rails | Tags: , , | 0 条评论, 1298 次阅读
Jul
25
2010
rails 中当我们用 scaffold 后,生成view的 new和edit 中的 form_for 为啥一样?
一样了怎么知道哪个是update?哪个是create呢?
类别:ruby & rails | Tags: , | 0 条评论, 1358 次阅读
Jul
13
2010
create_table 的参数 :options 处设置字符集
字段 非空、默认值、字符长度限制设置
add_index 用来设置索引,不可重复用 :unique 参数


class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users, :options=>"DEFAULT CHARSET=UTF8" do |t|
      t.string :User, :null=>false, :limit=>16
      t.string :Password, :null=>false, :limit=>40
      t.boolean :Status, :null=>false, :default=>1
      t.text :Comment
      t.timestamps
    end
    add_index :users, :User, :name=>"users_User_index", :unique=>true
  end

  def self.down
    drop_table :users
  end
end


类别:ruby & rails | Tags: , , , , | 0 条评论, 1315 次阅读
Jun
21
2010
环境:ruby 1.8.7、net/ssh 2.0.22、openssh 5.4、archlinux 2.6.32
问题1:PATH的问题,导致我们无法执行一些命令
现象:
我们net/ssh connection openssh后 exec!('echo $PATH') 返回的是 /usr/bin:/bin:/usr/sbin:/sbin
原因:
net/ssh 是 "user@notty" ,而 xshell这些 是 "user@pts/x"
这点我们可以通过 'ps aux|grep sshd' 来实时查看
查看后发现 xshell 认证后是 sshd: root@pts/0 ,而net/ssh 认证后是 sshd: [accepted]
[2010.6.4 19:00更新] 我把net/ssh用到rails中的时候,rails启动后是 sshd: root@notty,这个还真没想到能看到
引用一段说明
Quotation

//原文参见 http://www.javaeye.com/topic/402750
Ruby ssh only provide the "SSH" function, not term login.
If you check, you will see that the connection from ruby ssh is "user@notty", not like ssh command ("user@pts/x").
You have to do more to make an environment like manual login.

解决方法:

[root@vkill ~]# vi /etc/ssh/sshd_config
//添加这行
PermitUserEnvironment yes
[root@vkill ~]# vi ~/.ssh/environment
//添加类似这行,文件内容格式参见 /etc/environment
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/ruby-enterprise-1.8.7-2010.01/bin:/usr/local/bin:/usr/local/sbin
[root@vkill ~]# /etc/rc.d/sshd restart

结果:
现在再去 net/ssh 后看 $PATH 就是~/.ssh/environment中设置的了
类别:ruby & rails | Tags: , , , , | 1 条评论, 2048 次阅读
Jun
3
2010
前几天用 open3 的时候,做个执行 'passwd user' 命令的实验,因为这个要输入两次密码,既要执行两次 stdin ,后面看输出的时候,发现 stdout 为 nil ,而 stderr 才是我们看到的输出,当时也就没在意

昨天用 net/ssh 的时候,又拿执行 'passwd user' 命令实验
类别:ruby & rails | Tags: , , , , , , | 0 条评论, 1176 次阅读
Jun
2
2010
Pages: 10/34 First page Previous page 5 6 7 8 9 10 11 12 13 14 Next page Final page [ View by Articles | List ]