Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
@cqpx
VIP
NO. 40 / 2011-11-06

43 Topics / 362 Replies
0 Followers
0 Following
24 Favorites
No GitHub.
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 如何在 link_to 内加一个其他 html 标签 at February 09, 2012

    #13 楼 @niedhui 谢谢,又学了一手

  • 关于前后台公用一个 model 的问题 at February 09, 2012

    #3 楼 @d4rkl0rd 我平时就是这么操作的啊 form_for @user的路径会用user_path(@user),但是后台的路径应该用admin_user_path(@user)。 如果你没给前台的 user show 加路径的话,user_path(@user)就会出错。 form_for [:admin, @user]就会用admin_user_path(@user)

  • 关于前后台公用一个 model 的问题 at February 09, 2012

    我用的办法略显麻烦,还没发现刚好的办法....后台加 namespace:

    form_for [:admin, @user]
    
  • 如何在 link_to 内加一个其他 html 标签 at February 09, 2012

    你把参数打错了 content_tag(:i, "", :class=>'aa')

  • 如何在 link_to 内加一个其他 html 标签 at February 09, 2012

    #4 楼 @stephen 别加那个分号,ruby-china 的 bug,给我加了一个分号

  • 如何在 link_to 内加一个其他 html 标签 at February 09, 2012

    怎么多了个分号...

  • 如何在 link_to 内加一个其他 html 标签 at February 09, 2012

    <%= link_to content_tag(:i, "ha"), "http://google.com" %>

  • Wat,关于 Ruby 和 Javascript 比较荒唐的语言特征的搞笑视频 at February 09, 2012

    在 chrome 的 console 里试了一下,果然如此,哈哈哈

  • Mongoid 的 embedded_in 多层嵌入的自动保存是否存在问题? at February 09, 2012

    #4 楼 @lyfi2003 has_many 和 embeds_many 应用的场合不一样

    比如想看看 cqpx 这个 user 的注册时间是什么时候,可能会用类似这样的代码

    u = User.find 'cqpx'
    u.created_at
    

    如果是user embeds_many topics,在执行上面这段代码的时候,会把 cqpx 发过的所有 topic 都从数据库里读出来,因为 topics 全都嵌在 User 表里。大量无用数据就会跟着被取出来。 如果是user has_many topics就没有这个问题

    http://mongoid.org/docs/relations.html embeds_many 是 Embedded relations has_many 是 Referenced relations

    Embedded relations are associations between one or many objects where the child object is embedded within the parent in the same document in the database. 
    They can be extremely efficient when kept to a managable size in MongoDB since the total number of queries required to retrieve an entire object graph can be reduced to one.
    
    Referenced relations are associations between documents that reside in separate collections in MongoDB. 
    The link between the documents is handled similar to a relational database where a "foreign key" needs to be stored on one or both sides of the relation, but note that accessing a referenced relation required a separate query to the database since joins cannot be performed.
    
  • Mongoid 的 embedded_in 多层嵌入的自动保存是否存在问题? at February 09, 2012
    # Append one or many child addresses, saving them if the person is persisted.
    person.addresses << Address.new
    person.addresses.push(Address.new)
    person.addresses.concat([ address ])
    

    那句注释的意思是,如果 person 已经 persisted 了,就会保存 addresses 你给出的例子里面,user 还没有 persisted,这样应该可以

    user = User.create
    project = Project.new
    task = Task.new
    project.tasks << task
    user.projects << project
    

    代码里也是这个意思 https://github.com/mongoid/mongoid/blob/master/lib/mongoid/relations/embedded/many.rb#L26

    def <<(*args)
      docs = args.flatten
      return concat(docs) if docs.size > 1
      if doc = docs.first
        append(doc)
        doc.save if persistable? && !_assigning? #这里判断base如果persisted了,才会save
      end
    end
    
    def persistable?
      base.persisted? && !_binding?
    end
    
  • ShopQi 上线内测,中国版 shopify at February 08, 2012

    支持马哥!

  • Node.js 中文社区 at February 08, 2012

    感觉要快很多。。是因为机房更快还是 nodejs 比 rails 快?

  • 有没有什么异常监控的 gem 推荐? at February 08, 2012

    airbrake 真的不错,用吧

  • 广州 Ruby-China.org hackathon at February 07, 2012

    线上聊天系统,以前实现过,后来发现没用取消掉了https://github.com/huacnlee/ruby-china/commit/6562c1a6bd36b7ffaa4db2bf55fc96f50205f863

  • 刚刚跑完步回来! at February 04, 2012

    #12 楼 @saberma 尽量在橡胶地或者跑步机这样软一点的平面上跑。 长期跑步应该选择专业的缓冲力强的长跑鞋。特别是重一点的朋友更要注意保护膝盖。 我高中上学放学都用跑的,穿着帆布鞋跑了三年水泥地,我很喜欢长跑时突破极限的感觉。 结果现在下蹲的时候膝盖就痛,成了跑步膝 (http://www.guokr.com/article/55453/),跑步对我来说成了一种奢望。

  • 刚刚跑完步回来! at February 04, 2012

    我准备过段时间游泳 跑步伤膝盖

  • GitHub 的产品设计 at February 02, 2012

    这里还有几个关于 github 的东西。如果以后我能开公司,我也会贯彻 github 和 37signal 这些理念 http://zachholman.com/posts/how-github-works-hours http://zachholman.com/posts/how-github-works-asynchronous http://zachholman.com/posts/how-github-works-creativity http://speakerdeck.com/u/mojombo/p/optimizing-for-happiness

  • Ruby on Rails bundler 问题 at February 02, 2012

    用bundle install --local,就会从本机安装已经有的 gem,很快

  • 有没有好的开源项目,来收集目标网站的内容更新? at January 31, 2012

    需要根据目标网站定制吧

  • 用 haml 呼唤 huacnlee (我已决定使用 SLIM 替代 HAML 和 ERB) at January 29, 2012

    #31 楼 @makeyou 学 rails 之前我用的 nodejs,我更喜欢 jade 的语法,更简洁。haml over erb 不就是图个简洁嘛 而且根据 slim 网站上的 benchmark,性能比 haml 好

  • 用 haml 呼唤 huacnlee (我已决定使用 SLIM 替代 HAML 和 ERB) at January 29, 2012

    我也用 slim 代替了 haml

  • 能够给 controller 生成新的 action 么? at January 21, 2012

    我当时也有你这个疑惑。 你先凑合用着,等过段时间你就会发现没那必要。

    如果你之前生成的代码没有改动,可以再运行一次,就会把之前生成的覆盖

  • 如果这里的帐号和 twitter 不一样会怎样? at January 20, 2012

    这里的@和 twitter 上@没有关系

  • 手机发的,小偷卖 IPHONE4 手机 at January 16, 2012

    我妈也被模型机骗过几百块

  • mongoid 的 accepts_nested_attributes_for 怎么用 at January 16, 2012

    可以试试用 codecampo 实现自增 id 的方法看行不行,这个方法就不会覆盖 mongoid 默认的 BSON 格式,而是另外加一个 field 来数数 https://github.com/chloerei/code_campo/blob/master/app/models/user.rb https://github.com/chloerei/code_campo/blob/master/app/models/mongoid/number_id.rb

  • mongoid 的 accepts_nested_attributes_for 怎么用 at January 16, 2012

    #4 楼 @yakjuly 为什么你的 policy 的_id 是数字不是 BSON?会不会跟这个有关? 我这里用 anaf 是可以的https://github.com/cqpx/yakjuly

  • mongoid 的 accepts_nested_attributes_for 怎么用 at January 16, 2012

    在你需要 has_one/has_many 这样的从属关系,但是又不想再单独为被包含的对象建一个表的时候用。

    比如 user has_one profile,profile 包括 name,address,phone 等等

    你不想单独建一个 profile 表,但是全部作为 User 的属性又显得很乱,就可以把 profile 嵌入到 user 里面,实际上还在 user 表里,但是有了 has_one/has_many 这样的从属关系,逻辑上更清晰

    https://github.com/chloerei/code_campo/blob/master/app/models/user.rb https://github.com/chloerei/code_campo/blob/master/app/models/profile.rb

    淘宝的 User,UserCredit 也是这样的关系, http://open.taobao.com/doc/api_cat_detail.htm?cat_id=1&category_id=102 如果淘宝没用 mongodb 这样的文档型数据库,那么它就必须建一个 UserCredit 表, 用了 mongodb,就可以把 UserCredit 嵌入到 User 里

  • mongoid 的 accepts_nested_attributes_for 怎么用 at January 16, 2012

    关于 anaf,你的参数和文档里提到的不一致 http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

    params = { :member => {
      :name => 'joe', :posts_attributes => [
        { :title => 'Kari, the awesome Ruby documentation browser!' },
        { :title => 'The egalitarian assumption of the modern citizen' },
        { :title => '', :_destroy => '1' } # this will be ignored
      ]
    }}
    
    member = Member.create(params['member'])
    member.posts.length # => 2
    member.posts.first.title # => 'Kari, the awesome Ruby documentation browser!'
    member.posts.second.title # => 'The egalitarian assumption of the modern citizen'
    

    mongoid 里也是这种格式http://mongoid.org/docs/relations/nested_attributes.html

    简单说,就是你没用数组

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