Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
bobo
@bobo
会员
第 27861 位会员 / 2016-08-03

[email protected]
深圳
2 篇帖子 / 26 条回帖
1 关注者
1 正在关注
47 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 还有多少同学在做 Ruby 相关工作? at 2019年03月18日

    13

  • 初次启动 Rails 服务报错~~~~求助 at 2019年03月01日

    gem uninstall sqlite3 bundle install

  • Vue + Rails 做前后端分离,请问登录该如何处理呢 (原系统用的 Devise),恳请大佬们提建议 at 2018年07月10日

    我的做法是,用 has_secure_password 自己写登录验证,cancancan + rolify 做权限控制,kong 当 api gateway, login request 登录成功返回一个 jwt token,然后前端利用 token 通信

  • 这个弱鸡的换行问题 at 2017年12月11日

    我觉得应该用any?(&:present?)

  • Bundler.require 自动加载 Gemfile 怎么使用? at 2017年12月07日

    Thanks,正好解决了我的问题

  • Gemfile 如何搜索自己要的包 at 2017年11月08日

    https://ruby.libhunt.com/

  • Rails 如何删除 2 天前 数据库中的数据 at 2017年11月07日

    A.where("updated_at < '#{2.days.ago}'").delete_all

  • 送几本《Ruby on Rails 教程 (第 4 版)》纸质书 at 2017年10月31日

    攒个人品

  • 级联菜单的问题,二级联动效果 at 2017年10月23日

    view

    select_tag 'document_type_id', options_from_collection_for_select (@document_types, :id, :name), data:{remote: true, url: document_path}
    select_tag 'production_id',[]
    

    controller

    def document
        if params[:document_type_id]
         @productions = Production.where(document_id: params[:document_type_id])  
      end
    end
    

    document.js.erb

    $('#production_id').html('<%= j(options_from_collection_for_select @productions, :id, :name)%>')
    

    我在工作中一般是这么写的。你试试,可能要将select_tag 转换为对应的f.select

  • 级联菜单的问题,二级联动效果 at 2017年10月23日

    type_id: $ 中间隔个空格试试

  • 安装 Rails 环境时的报错 cannot load such file -- zlib,该如何解决呢 at 2017年09月21日

    reinstall ruby 试试

  • 安装 Rails 环境时的报错 cannot load such file -- zlib,该如何解决呢 at 2017年09月21日

    https://github.com/redis/redis-rb/issues/573

  • 求助一下,Rails 里面如何在 view 里面向控制器传递参数 at 2017年09月20日

    好奇怪的要求。。。用 rails 框架还不让用 rails 的一些推荐方法。

    <% @pd_list.each do |d| %>
    

    这句话有 Bug,一旦@pd_list 为 nil,就 500 error 了。 我喜欢用下面的方式写循环

    <% @pd_list.try(:each) do |d| %>
    
  • 求助一下,Rails 里面如何在 view 里面向控制器传递参数 at 2017年09月20日

    看的有点糊涂。首先路由不符合规范,其次 type 和 product 应该是一对多或者多对多关系,应该不用找起来这么复杂。

  • 级联菜单的问题,二级联动效果 at 2017年09月12日
    <script>
      $(function({
          $("#type_id").change(function(){
              $.ajax({
                  url: xxx_path,
                  type: 'get',
                  data: { type_id: $('#type_id').val() }
              }).success(data)({
                  $('xxx').html(data);
              })
          });
      }))
    <script>
    

    大概是这样子吧

  • 级联菜单的问题,二级联动效果 at 2017年09月08日
    $(".doc_obj").html("<%= f.collection_select :object_id, Product.all, :id, :name, class:"form-control" %>")
    

    jquery 可以插入 ruby 代码,只是不能再用f.collection_select了,因为f这个对象此时是不存在的,可以尝试用select_tag 或其他的 help 方法。也可以用 ajax 来做,把type_id 传入后台,生成想要的 html 后直接替换。

  • 在 Windows 下启动一个开发环境的项目会很麻烦吗? at 2017年08月29日

    我觉得用 rubymine 挺简单的。半小时到 1 个小时可以搞定。。盗版 key😷

  • 这是一个非常有趣的 Gem at 2017年07月31日

    应该不只是男孩子喜欢吧。。。😱

  • ActiveRecord establish_connection 不断切换 database config 会有什么恶劣的影响吗? at 2017年07月14日

    好像没影响。

  • ActiveRecord establish_connection 不断切换 database config 会有什么恶劣的影响吗? at 2017年07月14日
    # File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 878
    def establish_connection(config)
      resolver = ConnectionSpecification::Resolver.new(Base.configurations)
      spec = resolver.spec(config)
    
      remove_connection(spec.name)
    
      message_bus = ActiveSupport::Notifications.instrumenter
      payload = {
        connection_id: object_id
      }
      if spec
        payload[:spec_name] = spec.name
        payload[:config] = spec.config
      end
    
      message_bus.instrument("!connection.active_record", payload) do
        owner_to_pool[spec.name] = ConnectionAdapters::ConnectionPool.new(spec)
      end
    
      owner_to_pool[spec.name]
    end
    

    remove_connection(spec_name)

    Remove the connection for this class. This will close the active connection and the defined connection (if they exist). The result can be used as an argument for establish_connection, for easily re-establishing the connection.

  • ActiveRecord establish_connection 不断切换 database config 会有什么恶劣的影响吗? at 2017年07月14日

    thank you.

  • 请问 Ruby on Rails 有没有不用 Model 与 SQL 表对应也能直接操作数据库的类? at 2017年07月13日

    可以。

  • 请问 Ruby on Rails 有没有不用 Model 与 SQL 表对应也能直接操作数据库的类? at 2017年07月13日

    Sequel 这个 gem 可以参考下。https://github.com/jeremyevans/sequel

  • Ajax 里用 append 嵌入一段 Rails 代码 at 2017年07月13日

    rails 渲染 view 的时候会根据 erb 模板默认规则把代码进行转换,helper 方法和@实例变量会转换成静态值在页面显示,<%= f.select xxx %>会自动变成类似<select><option>的静态 html 代码,调用 ajax 方法的时候 f 这鬼东西根本就不存在了,这是服务器端的东西,用户看到的是客户端的静态页面,所以你可以用<select></select>标签来替代<%= f.select %>。如果是我,我会选择在 view 里面新建一个_select.html.erb,然后把你那段代码放进来,不要<f.select>,直接用select_tag,配合 rails 的 options_for_select,controller 里面 render file: '_select.html.erb',页面直接success(data){ append(data)}

  • Ajax 里用 append 嵌入一段 Rails 代码 at 2017年07月13日

    append 里面可以写 rails 代码。<%= f.select xxx %>里面的 f 是一个普通变量,不是实例变量无法进行转换。把f.select xxx在后台拼接而成再传给前端你试试。

  • Ruby On Rails 入门学习资料推荐 (希望大家有好的资料也分享一下) at 2017年04月28日

    RUA!

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