Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
Rei
@Rei
Admin
NO. 1 / 2011-10-28

[email protected]
深圳
189 Topics / 9169 Replies
732 Followers
0 Following
11 Favorites
中下水平 Rails 程序员
Reward
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
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 什么时候 Google 让河蟹了? at April 12, 2012

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

    找找个人设置

  • 关于 rails 操作 MYSQL 的问题 at April 12, 2012

    has_many :microposts, :foreign_key => "user_uid"

  • 关于 rails 操作 MYSQL 的问题 at April 12, 2012

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

    楼主再检查下拼写

  • 神奇的空格 at April 12, 2012

    #5 楼 @frankel good

  • ActionMailer 发不出去邮件 at April 12, 2012

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

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

  • 关于 rails 操作 MYSQL 的问题 at April 12, 2012

    class User first_user = Users.first

    类名打错了吧

  • model 中的虚拟属性 at April 11, 2012

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

  • rails 怎样使用迁移设定一个表的外键 at April 11, 2012

    #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 April 11, 2012

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

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

  • rails 怎样使用迁移设定一个表的外键 at April 11, 2012

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

  • 神奇的空格 at April 11, 2012

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

  • 求解:关于表间关联 at April 11, 2012

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

    控制器

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

    视图

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

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

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

  • 如何在不同的页面加载不同的 js 文件? at April 11, 2012

    #1 楼 @daqing 我也是这样

  • ruby-china 创建 notification 失败,怎么解? at April 11, 2012

    没看明白阿,你做了什么

  • 求解:关于表间关联 at April 11, 2012

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

  • 为啥不加上私信功能? at April 10, 2012

    #5 楼 @ericguo 我也这么觉得

  • 求解:关于表间关联 at April 10, 2012

    假设用这个结构

    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 April 10, 2012

    #7 楼 @douya0808 has_many :througth

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

  • 求解:关于表间关联 at April 10, 2012

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

  • 能不能给 mogonmapper 设置主键? at April 10, 2012

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

  • 新人请教一个比较奇怪的问题 at April 10, 2012

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


    看了下文档,好像还真有

    用

    home_mm_content_path(:id => post)
    
    
    

    试试

  • 新人请教一个比较奇怪的问题 at April 10, 2012

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

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

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

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

  • 给 Mongoid 加上 find_by_xxx 方法 at April 09, 2012

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

  • 怎么开始写前台的代码? at April 09, 2012

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

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

    证明懂 CSS 得空白起家

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

    改好了

  • ruby 所谓方法和消息怎么理解呢? at April 09, 2012

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

  • ruby 所谓方法和消息怎么理解呢? at April 08, 2012

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

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

    foo.new.send :bar

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

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