• 涨姿势了😀

  • 一个 UUID 的字符串,被解析成日期了啊😂

  • 唉,大湖名城也没有 ROR 工作啊......

  • 分母加 2

  • +1

  • 分母 +4096😁

  • 已入手

  • @w7938940 nice, 我之前没有想到,谢谢

  • 在 will paginate gem 中找到了原因,我修改了 action_view.rb 文件中的一个函数:

    def merge_get_params(url_params)
       if @template.respond_to? :request and @template.request and @template.request.get?
         symbolized_update(url_params, @template.params.is_a?(ActionController::Parameters)==true ? @template.params.to_unsafe_h : @template.params)
       end
       url_params
     end
    

    但是觉得这个方法并不好,希望大家能给出更好的解决办法

  • View 代码剪切:

    <div class="all-search">
      <form method="get" action="<%= send("search_#{@model.pluralize}_path") %>">
        <div class="col-sm-12">
          <div class="col-sm-4">
            机器号:
            <%= select_tag('downtime_record[machine_id]', options_from_collection_for_select(Machine.all, :id, :nr, @machine_id), include_blank: true) %>
          </div>
          <div class="col-sm-3">
            订单号:
            <input type="text" name="downtime_record[pd_bemerk]" value="<%= @pd_bemerk %>"/>
          </div>
          <div class="col-sm-4">
            停机代码:
            <%= select_tag('downtime_record[downtime_code_id]', options_from_collection_for_select(DowntimeCode.all, :id, :nr, @downtime_code_id), include_blank: true) %>
          </div>
        </div>
    
    
        <div class="col-sm-12">
          <div class="col-sm-4">
            <input type="submit" value="查 找" class="btn btn-primary" style="width: 150px;"/>
          </div>
        </div>
      </form>
    </div>
    
  • Controller 代码剪切:

    def search
      @condition=params[@model].to_unsafe_h
    
      query=model.all #.unscoped
      @condition.each do |k, v|
        if (v.is_a?(Fixnum) || v.is_a?(String)) && !v.blank?
          puts @condition.has_key?(k+'_fuzzy')
          if @condition.has_key?(k+'_fuzzy')
            query=query.where("#{k} like ?", "%#{v}%")
          else
            query=query.where(Hash[k, v])
          end
          instance_variable_set("@#{k}", v)
        end
    
        if v.is_a?(Hash) && v.values.count==2 && v.values.uniq!=['']
          values=v.values.sort
          values[0]=Time.parse(values[0]).utc.to_s if values[0].is_date? & values[0].include?('-')
          values[1]=Time.parse(values[1]).utc.to_s if values[1].is_date? & values[1].include?('-')
    
          query=query.where(Hash[k, (values[0]..values[1])])
          v.each do |kk, vv|
            instance_variable_set("@#{k}_#{kk}", vv)
          end
        end
      end
    
      if block_given?
        query=(yield query)
      end
    
      if params.has_key? "download"
        send_data(query.to_xlsx(query),
                  :type => "application/vnd.openxmlformates-officedocument.spreadsheetml.sheet",
                  :filename => @model.pluralize+".xlsx")
        #render :json => query.to_xlsx(query)
      else
        instance_variable_set("@#{@model.pluralize}", query.paginate(:page => params[:page]))
        render :index
      end
    end
    
    private
    # Use callbacks to share common setup or constraints between actions.
    def set_downtime_record
      @downtime_record = DowntimeRecord.find(params[:id])
    end
    
    # Never trust parameters from the scary internet, only allow the white list through.
    def downtime_record_params
      params.require(:downtime_record).permit(:fors_werk, :fors_faufnr, :fors_faufpo, :fors_lnr, :machine_id, :pk_sch, :pk_datum, :pk_sch_std,
                                              :pk_sch_t, :craft_id, :pd_teb, :pd_stueck, :pd_auss_ruest, :pd_auss_prod, :pd_bemerk, :pd_user,
                                              :pd_erf_dat, :pd_von, :pd_bis, :downtime_code_id, :pd_std, :pd_laenge, :pd_rf, :is_naturl,
                                              :pd_bemerk_fuzzy, :pk_datum_start, :pk_datum_end,:page)
    end
    

    View 代码剪切:

    <div class="col-sm-12">
      <div class="digg_pagination">
        <div class="page_info">
          <%= page_entries_info @downtime_records %>
        </div>
        <%= will_paginate @downtime_records, :container => true %>
      </div>
    </div>
    
    <table>
      <thead>
      <tr>
        <th>NO.</th>
        <th>工厂代码</th>
        <th>订单号</th>
        <th>订单序号</th>
        <th>Fors lnr</th>
        <th>机台号</th>
        <th>班次</th>
        <th>入账日期</th>
        <th>Pk sch std</th>
        <th>班组</th>
        <th>工艺</th>
        <th>标准操作工时(m)</th>
        <th>产量</th>
        <th>生产前报废</th>
        <th>生产过程中报废</th>
        <th>订单+序号</th>
        <th>账号</th>
        <th>实际生产日期</th>
        <th>停机开始</th>
        <th>停机结束</th>
        <th>停机代码</th>
        <th>停机时间(h)</th>
        <th>线长(mm)</th>
        <th>Pd rf</th>
        <th>是否系统添加</th>
        <th colspan="3"></th>
      </tr>
      </thead>
    
      <tbody>
      <% @downtime_records.each_with_index do |downtime_record, index| %>
          <tr>
            <td><%= index+@downtime_records.offset+1 %></td>
            <td><%= downtime_record.fors_werk %></td>
            <td><%= downtime_record.fors_faufnr %></td>
            <td><%= downtime_record.fors_faufpo %></td>
            <td><%= downtime_record.fors_lnr %></td>
            <td><%= downtime_record.machine.nr %></td>
            <td><%= downtime_record.pk_sch %></td>
            <td><%= downtime_record.pk_datum.localtime.strftime('%Y%m%d') %></td>
            <td><%= downtime_record.pk_sch_std %></td>
            <td><%= downtime_record.pk_sch_t %></td>
            <td><%= downtime_record.craft.nr %></td>
            <td><%= downtime_record.pd_teb %></td>
            <td><%= downtime_record.pd_stueck %></td>
            <td><%= downtime_record.pd_auss_ruest %></td>
            <td><%= downtime_record.pd_auss_prod %></td>
            <td><%= downtime_record.pd_bemerk %></td>
            <td><%= downtime_record.pd_user %></td>
            <td><%= downtime_record.pd_erf_dat.localtime.strftime('%Y%m%d') %></td>
            <td><%= downtime_record.pd_von.localtime.strftime('%Y%m%d  %H:%M:%S') %></td>
            <td><%= downtime_record.pd_bis.localtime.strftime('%H:%M:%S') %></td>
            <td><%= downtime_record.downtime_code.nr %></td>
            <td><%= downtime_record.pd_std %></td>
            <td><%= downtime_record.pd_laenge %></td>
            <td><%= downtime_record.pd_rf %></td>
            <td><%= downtime_record.is_naturl %></td>
            <td><%= link_to 'Show', downtime_record %></td>
            <td><%= link_to 'Edit', edit_downtime_record_path(downtime_record) %></td>
            <td><%= link_to 'Destroy', downtime_record, method: :delete, data: {confirm: 'Are you sure?'} %></td>
          </tr>
      <% end %>
      </tbody>
    </table>
    
    <div class="digg_pagination">
      <%= will_paginate @downtime_records, :container => false %>
    </div>
    
  • 回合肥炒房子怎么样?

  • 根在那边,现在上海漂着来,你在?

  • 合肥貌似很少搞 Ruby&Rails 的,唯一知道的是去年有个帖子,说在庐阳区吧

  • puts.....

  • 👍

  • 干掉你代码中的坏味道 at August 06, 2016

    赞一个

  • 👍 👍

  • Grape 写 API 发送文件 at June 14, 2016

    @zj0713001 对的,没有涉及权限😃

  • Grape 写 API 发送文件 at June 14, 2016

    @zj0713001 看到了,谢谢 但是我们结果讨论一致认为返回 URL 好点😃

  • Grape 写 API 发送文件 at June 14, 2016

    @noob OK, 3Q😃

  • Grape 写 API 发送文件 at June 14, 2016

    @huacnlee 这是我第一次发贴,大神能解答,很开森 Ing😐 ,其实这个问题我查了很多,基于 Grape 作为 API 的答案我只得到这个方案,我就告诉客户端的同事,我能给你这样的 Respond,同事也是菜鸟,告诉我:你都给我 URL 了,为啥不能直接给我文件,我不会搞。那我就想,是不是我搜索的方式有问题?于是边继续扩大范围搜索,边到社区来提了我的第一个问题😃

  • grape 写 api 发送文件 at June 14, 2016

    大神,关于这个问题最后怎么解决的?我是新手,也遇到了相同的需求,API 也是用的 Grape,APP 客户端想从服务器下载文件,目前没有找到好的方法,现在正准备 API 返回文件的 URL,让 APP 自己去下载

  • 赞!

  • 支持

  • lzding

  • 我 DOTA 还行。。。

  • Ruby 开发遇到的坑 at November 19, 2015

    freeze 冻结的是一块内存,这么理解对吗?

  • +1