Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
倍儿硬
@will_c_j
会员
第 19071 位会员 / 2015-05-28

0 篇帖子 / 32 条回帖
2 关注者
2 正在关注
12 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • Ruby China 7 岁生日快乐 at 2018年10月29日

    👍 👍 👍 👍 👍 👍 👍 👍

  • 送几本《Rails 5 敏捷开发》 at 2018年01月26日

    支持!

  • 为什么只有在 Chrome 上会出现 ActionController::InvalidAuthenticityToken 这个错误 at 2017年11月06日

    head 里加上 <%= csrf_meta_tags %>

    form 里把 authenticity_token:$("meta[name='csrf-token']").attr("content") 传过去应该就好了

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

    👍 👍 👍

  • 请教关于 js 点击事件绑定后,如何在 HTML 中 显示 js 参数 的问题 at 2017年10月23日
    function showInput(){
      $("#display").html($("#search_date_from").val() +"----" +$("#search_date_to").val())
    }
    showInput()
    

    你帖子上的 HTML 那 display 写错了

  • 从零学习 Rails 记录 (第一天) at 2017年08月24日

    迁移数据是 rake db:migrate?

  • 关于 Rails 路由,自定义添加后,报 “ActionController::RoutingError (No route matches {:action=>xxx,:controller=>"xxxx})"“ at 2017年08月16日

    可以配置成那样的形式,你可以看看这个 https://ihower.tw/rails/routing.html

  • 关于 Rails 路由,自定义添加后,报 “ActionController::RoutingError (No route matches {:action=>xxx,:controller=>"xxxx})"“ at 2017年08月16日

    如果你的 action 里没有 render 或 redirect_to 会默认去找与你 action 同名的 template

    不是必须创建 template, 你可以在你写的 action 里做 render 或 redirect_to,指定跳转

  • 关于 Rails 路由,自定义添加后,报 “ActionController::RoutingError (No route matches {:action=>xxx,:controller=>"xxxx})"“ at 2017年08月16日

    那你这么写吧, #隔开 controller action

    post "/popup_signup_log" => "index#popup_signup_log"

    get "/invitation_new" => "index#invitation_new"

  • 关于 Rails 路由,自定义添加后,报 “ActionController::RoutingError (No route matches {:action=>xxx,:controller=>"xxxx})"“ at 2017年08月16日

    member 换成 collection

    :member 是对单个实体进行操作,创建路由格式是: /:controller/:id/:your_method

    :collection 是对实体集合进行操作,创建路由格式是: /:controller/:your_method

  • 如何在 application.html.erb 里面定义变量在所有的页面里面都能用 at 2017年08月16日

    你贴的代码是 layouts/applition.html.erb 吧,@list_hs 是你访问的 controller 下的 action 里定义的

    我的想法: 你在 application_controller.rb 里面写个 action, 例:

    def get_list_hs
        return  XXX
    end
    

    之后在你访问的 action 里加上

    @list_hs = get_list_hs
    

    先提条件是 你的 controller < ApplicationController

  • 关于 Rails 外键的问题 at 2017年08月10日

    Follow Model 里加上下面代码应该就可以了吧

    可以看看 https://ruby-china.org/topics/19619

    belongs_to :follower, :class_name => "User", :foreign_key => "follower_id"  #关注者
    belongs_to :following, :class_name => "User", :foreign_key => "following_id"  #被关注者
    
  • 关于 Rails 的 Model 和 Controller 之间传值的问题? at 2017年08月04日

    是不是可以写成这样?

    validates :platform, presence: true, if : check_platform
    
    
    def check_platform
    
    end
    
  • 树形结构数据表如何查询最底一层的所有数据 at 2017年07月19日
    第一层 :first_level = ProductCatalog.where("parent_id is null")
    第二层 :second_level = ProductCatalog.where(parent_id:first_level.collect(&:id))
    第三层 :third_level = ProductCatalog.where(parent_id:second_level.collect(&:id))
    第四层 :fourth_level = ProductCatalog.where(parent_id:third_level.collect(&:id))
    
  • 树形结构数据表如何查询最底一层的所有数据 at 2017年07月18日

    我觉得你就是要找 parent_id 为最大的集合 试试下面的查询

    ProductCatalog.select("product_catalogs.*").order("parent_id desc").group_by(&:parent_id).first[1]
    
  • params.require 为什么过滤失效 at 2017年07月05日

    我记得 params 是 ActionController::Parameters 并不是 ActiveRecord 所以好像不能这么用

  • params.require 为什么过滤失效 at 2017年07月05日

    过滤前的内容里 key 都是 String ,试试用 string

    params.require("person").permit("name", "password","adress") 
    
  • Ruby 中 each.do 集合遍历问题 at 2017年07月03日

    each_with_index do |r, i|

  • 关于一个字符串包含另外一个字符串中的相同数值的判定问题 at 2017年07月03日
    A = "01 02 03 04 05 06".split(" ")
    B = " 05 06".split(" ")
    case (A-B).size
    when 0
    # 一等奖
    when 1
    # 二等奖
    
    
  • 怎样实现整数定时任务? at 2017年06月30日

    你可以试试 gem whenever

    every 10.minutes do
      runner "XXXXXXX"
    end
    
  • 关于模型问个特别小白的问题 at 2017年06月29日

    可以,一样的

  • 关于模型问个特别小白的问题 at 2017年06月29日

    你可以在 Model 类里写一个实例方法来实现 ,就不用再别名了

    def a
      name
    end
    
    Model.first.a
    
  • 写 deep health check 的时候遇到 template is missing 的问题 at 2017年06月28日

    我觉得原因是

    result = ActiveRecord::Base.connection.select_value("XXXXXXXXXXXXXXX")
    

    报错了,没有走到 render 所以会有 template is missing,你可以试试在 rescue 里面在加个 render 试试

    render :nothing => true
    
  • 联表查询写法的疑问 at 2017年06月23日

    你用的是我第一个给你的查询吧,那个有 N+1 问题,我给你删了

    #<Channel id: 1, name: "Hello Focus", introduction: "这里是Focus的频道 😀", channel_type: "picture", intimity: "masses", user_id: 1, created_at: "2017-06-22 15:26:20", updated_at: "2017-06-22 15:26:20">, 5]
    

    最后那个 5 就是 p_count

    用最新给你的这个吧,试试

    Channel.joins(:posts).select("channels.* , count(posts.channel_id) as p_count ").group("posts.channel_id").order("p_count desc")
    
  • 联表查询写法的疑问 at 2017年06月23日
    Channel.joins(:posts).select("channels.* , count(posts.channel_id) as p_count ").group("posts.channel_id").order("p_count desc")
    

    p_count 可以。出来

  • 如何指定下拉列表中的值 at 2017年06月20日

    😫 😫 😫

  • 如何指定下拉列表中的值 at 2017年06月20日

    首先,我觉得你部门的 select 的 value 应该就是@user.department.id,如果你不需要其他部门信息就不需要再次查询 department 表 其次,你的@departments参数应该是@department

    我的拙见 1,现在 controller 里添加 json 返回,例:

    format.json { render :json => { :department_id => @user.department.id }
    

    2,js 里添加 callback,把从 controller 返回的 id 赋值给你的 department 的 select 的 value 例:

    $("#user_id").on("change", function () {
        var options=$("#user_id option:selected");
        var selected = options.val();
        $.ajax({
            url: "new",
            data: {selectedid: selected},
            success: function(data){
                  $('#department_select').val(data.department_id);
              }
        });     
    });
    

    大概就是这个实现吧

  • [北京][八里庄] 星途无限招聘 Web 开发者 (并提供实习机会)[名额已满] at 2016年08月04日

    可以有,顶!d=====( ̄▽ ̄*)b

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