未定义的方法`txnid'用于[]:Array

时间:2015-03-26 03:38:24

标签: ruby-on-rails ruby-on-rails-3

我正在尝试在表格中显示唯一的trasactions。实际上我也有一些重复的交易。当我在桌子上拨打txnid.uniq时,我收到以下错误。(@ all_settlement_details)

   undefined method `txnid' for []:Array

Transaction.html.erb

          <tr>
          <th>Merchant Name</th>
          <th>Transaction ID</th>
          <th>Payment Mode</th>
          <th>Amount</th>
          <th>Status</th>
          <th>Transaction Fee</th>
          <th>Discount</th>
          <th>Additional Charges</th>
          <th>Added On</th>
        </tr>
        </thead>
        <tbody id="details">
        <% @all_settlement_details.txnid.uniq.each do |sd|  %>
            <tr>
              <td><%= sd.merchantname %></td>
              <td><%= sd.txnid %></td>
              <td><%= get_mode_ui.value(sd.mode) %></td>
              <td><%= sd.amount %></td>
              <td><%= get_status(sd.status) %></td>
              <td><%= sd.mer_service_fee %></td>
              <td><%= sd.discount %></td>
              <td><%= sd.additional_charges%></td>
              <td><%= get_added_on_date sd.addedon %></td>
            </tr>
        <% end %>
        </tbody>

traansactions_helper.rb

 def get_all_settlement_details
    # Offset increments by 10 and Limit remains 11
    _txn_filter_scope = {'transaction_status' => ["status", (params[:transaction_status].split(',') rescue nil)],
                         'payment_options' => ["payment_options", (params[:payment_options].split(',') rescue nil)],
                         'transaction_id' => ['transaction_id', params[:transaction_id]],
                         'transaction_amount' => ['amount_range', ((params[:transaction_amount].split(',')[0] || 0) rescue nil), ((params[:transaction_amount].split(',')[1] || 100000000) rescue nil)],
                         'merchant_mid' => ['merchant_mid',params[:merchant_mid]],
                         'merchant_name' => ['merchant_name', params[:merchant_name]],
                         'clicks' => ['txn_offset', ((params[:clicks].to_i)*10 rescue 0)]
    }
    method_array = [['settlement_details'],["date_filter", @start_date, @end_date]]
    method_array << ["txn_limit", 11] unless @csv_format
    method_array << ['merchant_mid', @merchant_mid] if @merchant_mid
    records = call_scope_methods_dynamically(method_array, _txn_filter_scope)
    records.empty? ? nil : records
  end

# Get the multiple payment modes of a trasaction, if any.
  def get_multiple_payment_modes txn_id, payment_modes
    debugger
    PG_MODE
    @all_modes = []
    @total_trasactions = []
    _multiple_modes = {'transaction_id' => ['transaction_id', params[:transaction_id]]}
     methods = [['settlement_details'],['merchant_mid'],['transaction_id'], ['payment_modes']]
     @total_transactions << ['transaction_id', txn_id] if payment_modes.present?
       if @total_transactions[:payment_modes] > 1
          payment_modes.each do |m|
          @all_modes << m
        end
        @all_modes
      end  
  end

  def get_uniq_transactions txn_id
    @all_modes = []
    uniq_tr = @all_settlement_details.txn_id.uniq
    uniq_tr.payment_modes.each do |m|
      @all_modess << m
    end
  end

如何修复此错误并仅显示唯一的交易?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

从我看到的情况来看,我最好的猜测是你在txnid上呼叫Array,很明显,你会看到这个错误。

此错误可能来自您的视图模板,您在txnid上呼叫@all_settlement_details,但该模板不可用。

您可能需要的是,@all_settlement_details.uniq.pluck(:txnid)代替@all_settlement_details.txnid.uniq在视图模板中。

PS:我不希望在帮助器中有这个逻辑,因为它在应用程序的视图中共享。相反,我想在这里使用装饰器(draper / hand rolled plain ruby​​ object)。