Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Rei
@Rei
管理员
第 1 位会员 / 2011-10-28

[email protected]
深圳
189 篇帖子 / 9169 条回帖
732 关注者
0 正在关注
11 收藏
中下水平 Rails 程序员
打赏作者
GitHub Public Repos
  • writings 941

    [Closed] Source code of writings.io

  • alipay 732

    Unofficial alipay ruby gem

  • code_campo 291

    [Closed] Source code of http://codecampo.com

  • asciidoctor-pdf-cjk-ka... 101

    **no longer maintained**

  • geeknote 34

  • asciidoctor-htmlbook 31

    Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents to HTMLBook docu...

  • material-ui 17

  • rich-text-editor 12

  • htmlrenderer 12

  • rails-chatgpt-demo 8

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 什么时候 Google 让河蟹了? at 2012年04月12日

    因为启用了 Google 的安全搜索功能

    找找个人设置

  • 关于 rails 操作 MYSQL 的问题 at 2012年04月12日

    has_many :microposts, :foreign_key => "user_uid"

  • 关于 rails 操作 MYSQL 的问题 at 2012年04月12日

    前面是 Users#microposts 6 楼是 User#micropost

    楼主再检查下拼写

  • 神奇的空格 at 2012年04月12日

    #5 楼 @frankel good

  • ActionMailer 发不出去邮件 at 2012年04月12日

    就是证书的问题,怎么装单独一个证书我也不懂,可以围绕 ruby openssl certificate 搜搜一下

    或者不安全的把校验关掉 OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

  • 关于 rails 操作 MYSQL 的问题 at 2012年04月12日

    class User first_user = Users.first

    类名打错了吧

  • model 中的虚拟属性 at 2012年04月11日

    …… 这就是 accessor 而已阿,怎么会有性能问题

  • rails 怎样使用迁移设定一个表的外键 at 2012年04月11日

    #5 楼 @413472212 你得先放下以数据库为中心的建模思路。ActiveRecord 有一套惯例,例如 User 和 Book 模型,对应 users 表和 books 表。

    # 表结构
    # users(id, ...)
    # books(id, user_id, ...)
    
    class User
      has_many :books
    end
    
    class Book
      belongs_to :user
    end
    
    # 使用场景
    user = User.new
    book = Book.new
    user.books << book
    user.save
    
    

    这样来完成数据保存。Rails 是先考虑模型层的建模,然后再根据模型层来准备数据库结构。可以看到因为在代码里面都是使用已有的数据对象来设置关联的,不会直接往数据库插入关联键的值。

    foreign_key 参数是指如果 books 变成了 (id, author_id, ...) 这样的结构,而需要用 author_id 和 User 模型建立关联,就需要用

    class User
      has_many :books, :foreign_key => :author_id
    end
    
    class Book
      belongs_to :user, :class_name => 'User', :foreign_key => :author_id
    end
    
    

    更多资料参考官方引导 http://guides.rubyonrails.org/association_basics.html

  • rails 怎样使用迁移设定一个表的外键 at 2012年04月11日

    #3 楼 @413472212 模型层的 belongs_to 只添加了模型层的关联方法,不会在数据库层加外键关联。不过在 Rails 社区习惯不依赖数据库而只做模型层关联。如果认为应用环境需要数据库层的关联校验,也可以加上数据库外键。

    :foreign_key 参数只是用来设置关联字段和关联名称不一致时的情况。

  • rails 怎样使用迁移设定一个表的外键 at 2012年04月11日

    用原生 SQL,例子 http://guides.rubyonrails.org/migrations.html#using-the-up-down-methods

  • 神奇的空格 at 2012年04月11日

    前几天我也遇到了,用 nokogiri 处理过的 html,&nbsp;会被 unicode nbsp 替换 http://en.wikipedia.org/wiki/Non-breaking_space

  • 求解:关于表间关联 at 2012年04月11日

    实例变量被重复赋值了。应该先在控制器拿到@arrangements,遍历交给视图

    控制器

    @arrangements = Arrangement.includes(:teacher, :banji, :kecheng).all
    
    
    
    
    

    视图

    <% @arrangements.each do |arrangement| %>
      <%= "#{arrangement.teacher.name} #{arrangement.banji.name} #{arrangement.kecheng.name}" %>
    <% end %>
    
    
    
    
    
  • 关于类似网易评论盖楼的数据库设计 at 2012年04月11日

    Trees in MongoDB http://www.mongodb.org/display/DOCS/Trees+in+MongoDB

    不单是说 mongodb,还说了其他设计思路

  • 如何在不同的页面加载不同的 js 文件? at 2012年04月11日

    #1 楼 @daqing 我也是这样

  • ruby-china 创建 notification 失败,怎么解? at 2012年04月11日

    没看明白阿,你做了什么

  • 求解:关于表间关联 at 2012年04月11日

    #16 楼 @douya0808 是的。限制存入用 validates

  • 为啥不加上私信功能? at 2012年04月10日

    #5 楼 @ericguo 我也这么觉得

  • 求解:关于表间关联 at 2012年04月10日

    假设用这个结构

    Teacher (...)
    Course (...)
    SchoolClass (...)
    Arrangement (teacher_id, course_id, school_class_id)
    
    
    class Teacher
      has_many :arrangements
      has_many :courses, :thougth => :arrangements, :uniq =>true
      has_many :school_classes, :thougth => :arrangements, :uniq =>true
    end
    
    class Course
      has_many :arrangements
      has_many :teachers, :thougth => :arrangements, :uniq =>true
      has_many :school_classes, :thougth => :arrangements, :uniq =>true
    end
    
    class SchoolClass
      has_many :arrangements
      has_many :teachers, :thougth => :arrangements, :uniq =>true
      has_many :courses, :thougth => :arrangements, :uniq =>true
    end
    
    class Arrangement
      belongs_to :teacher
      belongs_to :course
      belongs_to :school_class
    end
    
    # teacher 有课的班
    teacher.school_classes
    
    

    刚忘了说还有 :uniq 这个参数,用来去掉重复。

    我觉得这个结构是比较灵活的,熟悉 sql 的话可以做各种关联查询。

  • 求解:关于表间关联 at 2012年04月10日

    #7 楼 @douya0808 has_many :througth

    http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association

  • 求解:关于表间关联 at 2012年04月10日

    Teacher (...) Course (...) SchoolClass (...) Arrangement (teacher_id, course_id, school_class_id)

  • 能不能给 mogonmapper 设置主键? at 2012年04月10日

    这是 mongodb 的特性,_id 不能去掉

  • 新人请教一个比较奇怪的问题 at 2012年04月10日

    #5 楼 @BBQ 这样应该是没有 home_mm_content_path 这个方法的,是不是还有别的路由


    看了下文档,好像还真有

    用

    home_mm_content_path(:id => post)
    
    
    

    试试

  • 新人请教一个比较奇怪的问题 at 2012年04月10日

    我奇怪匿名路由怎么会有 url herlper。

    楼主看的资料旧了,现在不会用 ':controller(/:action(/:id(.:format)))' 这样的匿名路由。

  • Git pull 强制覆盖本地文件,命令是什么啊? at 2012年04月10日

    用法有问题,Gemfile.lock 变更了就 commit 进去阿

  • 给 Mongoid 加上 find_by_xxx 方法 at 2012年04月09日

    这个实现确实不如 ActiveRecord 里面那个,AR 的实现是第一次使用这个方法的时候用 define_method 生成一个,以后就是普通方法调用了。

  • 怎么开始写前台的代码? at 2012年04月09日

    bootstrap 的定制难度很大,就像交给你颜料把一副现成的画涂成另一个

    compass 看了下文档,api 太庞大了

    证明懂 CSS 得空白起家

  • 关于酷站:我提交的两个网站,我把分类看错了。现在在 Ruby 社区里面,麻烦帮我改到国内商业网站 at 2012年04月09日

    改好了

  • ruby 所谓方法和消息怎么理解呢? at 2012年04月09日

    #3 楼 @jiffies 是的。对象后面加点调用的都是方法。

  • ruby 所谓方法和消息怎么理解呢? at 2012年04月08日

    抽象概念而已,来源于 smalltalk,其实怎么说都可以。

    ruby 有个方法 send,可以这样调用一个方法

    foo.new.send :bar

    如果理解为消息就觉得这个方法很贴切了。

  • 上一页
  • 1
  • 2
  • …
  • 246
  • 247
  • 248
  • 249
  • 250
  • …
  • 273
  • 274
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English