Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
saiga
@saiga
会员
第 4375 位会员 / 2012-11-05

[email protected]
深圳
19 篇帖子 / 701 条回帖
14 关注者
1 正在关注
63 收藏
请认准唯一指定邮箱:aiasfina#hotmail.com
GitHub Public Repos
More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 在百度输入几个字,就出来一堆的下拉条,这是什么技术 at 2014年05月19日

    前端直接用 jquery 插件也可以。后端涉及分词和前缀匹配,直接上全文吧,es 好像内置了

  • 问一个 ruby 模型中关系数据库的问题。 at 2014年05月19日

    #6 楼 @so_zengtao belongs_to 的 foreign_key 是在当前表的。这个用 一对多来解释比较清晰

    class Event < ActiveRecord::Base
        has_many :attendees # 複數
        #...
    end
    
    class Attendee < ActiveRecord::Base
        belongs_to :event # 單數
    end
    

    以上图和代码来自 rails 实战圣经

  • 问一个 ruby 模型中关系数据库的问题。 at 2014年05月19日

    #3 楼 @so_zengtao 我还是把 1 楼删掉免得误导楼主了= =

    楼主定义的应该是 product 属于 type,detail 属于 product。

    而外键是定义在从属的那张表,也就是 product 表里面的 product_type_id 和 product_detail 里的 product_id。

    所以应该是

    class Product < ActiveRecord::Base
      validates :product_type_id, presence: true
    
      belongs_to :product_type, foreign_key: :product_type_id, class_name: "ProductType"
      has_one :product_detail, foreign_key: :product_id, class_name: "ProductDetail"
    
    end
    
    
  • JavaScript cheat Sheet at 2014年05月18日

    #6 楼 @yfractal 这个是 IEEE 定下来的标准:NaN 不等于他本身。虽然挺坑的...

    var a = NaN;
    a == a; // false
    
  • JavaScript cheat Sheet at 2014年05月18日

    parseInt('four11') 虽然是 NaN,但不等于 NaN.....

  • JavaScript cheat Sheet at 2014年05月18日

    #3 楼 @chenge js 的函数是第一类值,本身已经已经具备块的功能

    [1,2].map(function(i) { return i*2; })
    

    块,高阶函数,匿名内部类说到底都是一类东西,可以作为参数传递,返回,可以构建闭包。只是写法不同。

  • JavaScript cheat Sheet at 2014年05月18日

    #1 楼 @chenge 函数。

  • Rails 4 数据关联问题 at 2014年05月17日

    数据问题。没有与 userid 对应的 book 记录。检查一下数据

    User.where.not id: Book.pluck(:user_id)
    
  • mount 方法是干嘛用的? at 2014年05月16日

    http://ruby-china.org/topics/15102

    其中可以看看 mount 方法的作用:可以把不同的 servlet mount 不同的 url 上,形成一个路由表。

  • ActionController::UnknownFormat 的问题无法解决 at 2014年05月16日

    @people.update(user_params) 返回 false 了?

  • 你们是如何一步步成为学会编程的? at 2014年05月16日

    已经准备大师球,高手快出来!

  • 关于 Rails 业务逻辑是放在 Model 里面还是 Controller 里面呢? at 2014年05月16日

    #4 楼 @egg_show 看具体情况,数据处理是业务相关还是其他。一般涉及业务不会只有一两行,不建议放到 controller,有时甚至 model。与 view 相关的会放到 helper 或直接写在 view 里

  • 关于 Rails 业务逻辑是放在 Model 里面还是 Controller 里面呢? at 2014年05月16日

    rails 是充血模型,业务逻辑一般放model,controller 只处理请求和跳转。

  • kaminari 做 api 的分页怎么做? at 2014年05月15日

    其实这个可以直接看源码, paginate 这个方法肯定要调用 current_page 和 total_page ,直接看它实现就可以了。

    products.current_page
    products.total_page
    
  • protect_from_forgery at 2014年05月14日

    #2 楼 @hiveer get 请求不会拦截的。判断 get 还是 post 用 request,method == 'GET'

  • protect_from_forgery at 2014年05月14日

    google

    For individual actions, you can do:

    protect_from_forgery :only => [:update, :delete, :create]
    #or
    protect_from_forgery :except => [:update, :delete, :create]
    

    For an entire controller, you can do:

    skip_before_filter :verify_authenticity_token
    
  • 新人最近想入手 MBA,求推荐!谢谢! at 2014年05月14日

    #5 楼 @ailen 我倒是被 mac 摧残了一个月...

  • Rails 有没有简单的客服 Gem 呢? at 2014年05月13日

    即时性的?应该没有现成的 直接用付费三方的

  • Performance Differences in Ruby at 2014年05月12日

    :plus1:

  • [已解决] 使用 CarrierWave-Upyun 上传图片时发生 RestClient::Unauthorized (401 Unauthorized) 错误 at 2014年05月12日
    Completed 500 Internal Server Error in 1645ms
    RestClient::Unauthorized (401 Unauthorized):
    

    虽然没用过,不过日志显示这两个那应该是网络错误没跑了。 这个 gem 把返回的 resp 忽略 了,我用的是 rubymine,可以直接跳进 gem 源码里设断点,你可以试试模仿 store! 方法手动提交看看

  • readable, _, _ = IO.select (sockets) 的语法怎么讲? at 2014年05月12日

    并行赋值,下划线表示忽略

  • 如何简单地去掉代码的注释 at 2014年05月10日

    google: sed remove ruby comment

    sed -e 's/#.*$//' -e '/^$/d' inputFile
    
  • [已解决] 使用 CarrierWave-Upyun 上传图片时发生 RestClient::Unauthorized (401 Unauthorized) 错误 at 2014年05月10日
    401 Unauthorized
    
    访问未授权
    
    出现该错误的可能有:
    
    操作员或密码错误
    空间名错误
    其他错误(可从接口返回的 BODY 中获取详细信息)
    

    upyun 401,看看 restclient 发出的 request 和 response

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